!CVBVDaPiHphjTxEKuI:matrix.org

opsdroid-general

105 Members
32 Servers

Load older messages


SenderMessageTime
10 Jul 2020
@gitter_law:matrix.orgLee W (Gitter) alright, more skill-development questions. Is it possible/wise to try to use config[] variables during skill/class instantiation? 21:49:20
@gitter_law:matrix.orgLee W (Gitter) example: 21:49:21
@gitter_law:matrix.orgLee W (Gitter)
class Infrabot(Skill):
  stripe = config['endpoint_url'].split('.')[1]
21:49:40
@gitter_law:matrix.orgLee W (Gitter) endpoint_url is set in configuration.yaml, and is of the form https://endpoint.environment.mycompany.com. I want to be able to pull environment from it, as that is a reliable indicator of, well, the environment :-) 21:50:27
@gitter_law:matrix.orgLee W (Gitter)I need it to populate a few other methods later in the skill, it would be nice if I could set it as a class variable21:50:59
@gitter_law:matrix.orgLee W (Gitter) oh, the above code fails with NameError: name 'config' is not defined, fwiw 21:51:22
11 Jul 2020
@fabiorosado:matrix.orgFabioRosadoYou can access your skill config by using self.config (if you are using a class based skill). Also you should be able to get the user from memory 🤔03:06:13
14 Jul 2020
@oleg:fiksel.infoOleg Jacob Tomlinson (Slack): 👍️ https://medium.com/rapids-ai/introducing-frigate-a-documentation-generation-tool-for-kubernetes-1791854031a1 20:40:11
@oleg:fiksel.infoOleg(sorry for offtopic)20:40:38
@gitter_law:matrix.orgLee W (Gitter) how should I go about writing a 'does this key exist' method for objects in Opsdroid.memory? 20:43:54
@gitter_law:matrix.orgLee W (Gitter) this does not work, at all, and I'm exceptionally frustrated in trying to figure out why:
  async def _is_validjwt(self, opsdroid, config, message):
    _LOGGER.info(f"Checking for valid JWT token")
    return message.user in self.opsdroid.memory
20:44:44
@gitter_law:matrix.orgLee W (Gitter)

if I add a breakpoint via

  async def _is_validjwt(self, opsdroid, config, message):
    _LOGGER.info(f"Checking for valid JWT token")
    breakpoint()
    return message.user in self.opsdroid.memory

and start trying to mess around, nothing makes sense

20:45:24
@gitter_law:matrix.orgLee W (Gitter) for example, earlier in the code I insert into self.opsdroid.memory with
await self.opsdroid.memory.put("lwhalen", "somelongstring")
20:46:50
@gitter_law:matrix.orgLee W (Gitter)and if I try to pull that out later in the same method, it works great20:47:03
@gitter_law:matrix.orgLee W (Gitter)but as soon as I exit that method and try something else, it acts like never existed20:47:22
@gitter_law:matrix.orgLee W (Gitter) for example: at that 'breakpoint()' above, I get the following response to memory.get():
(Pdb) await self.opsdroid.memory.get("lwhalen") 
*** SyntaxError: 'await' outside function
20:48:20
@gitter_law:matrix.orgLee W (Gitter) which is weird to me, because I'm inside an async def _is_validjwt() block 20:48:56
@gitter_law:matrix.orgLee W (Gitter) trying it without the await gives me
(Pdb) self.opsdroid.memory.get("lwhalen") 
<coroutine object Memory.get at 0x1118af290>
/Users/lwhalen/Library/Application Support/opsdroid/opsdroid-modules/skill/infra-api/__init__.py:1: RuntimeWarning: coroutine 'Memory.get' was never awaited
  from opsdroid.skill import Skill
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
20:49:20
@gitter_law:matrix.orgLee W (Gitter)this is opsdroid 0.19.0, Python 3.7.7, etc20:50:04
@fabiorosado:matrix.orgFabioRosado

Instead of doing return message.user in self.opsdroid.memory you will hVe to do await self.opsdroid.memory.get() if you have a big list of names you can assign a variable on that expression and then do the return message.user in <var name>

I have built a skill that uses opsdroid memory heavily want to have a look at it?

21:00:59
@gitter_law:matrix.orgLee W (Gitter)yes please! 21:03:04
@gitter_law:matrix.orgLee W (Gitter) why does pdb return a SyntaxError when I run await self.opsdroid.memory.get("lwhalen") from inside PDB? 21:04:48
@_slack_opsdroid_U5MK1BW83:matrix.orgJacob Tomlinson (Slack) If a key doesn't exist it will return None 21:33:55
@_slack_opsdroid_U5MK1BW83:matrix.orgJacob Tomlinson (Slack) So you could check if it returns None 21:34:21
@gitter_law:matrix.orgLee W (Gitter) I've gotten it to DWIW with
  async def _is_validjwt(self, opsdroid, config, message):
    _LOGGER.info(f"Checking for valid JWT token for {message.user}")
    jwt = await self.opsdroid.memory.get(message.user)
    if jwt is None:
      _LOGGER.info(f"No token found")
      return False
    else:
      _LOGGER.info(f"found token")
      return True
21:35:29
@gitter_law:matrix.orgLee W (Gitter)thanks guys 21:35:31
@gitter_law:matrix.orgLee W (Gitter) I'm still curious as to why pdb returns a SyntaxError when I run await self.opsdroid.memory.get("lwhalen") from inside PDB? 21:35:56
@fabiorosado:matrix.orgFabioRosado This is the skill I mentioned https://github.com/FabioRosado/skill-twitch-game/blob/master/init.py 21:53:43
@_slack_opsdroid_U5MK1BW83:matrix.orgJacob Tomlinson (Slack) pdb doesn't support async python yet 22:29:57
15 Jul 2020
@akshays274:matrix.orgakshays274 joined the room.07:33:27

There are no newer messages yet.


Back to Room List