Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@register_event(NotanEvent)
def send_my_event(self, event):
pass
@register_event(Message)
async def send_message(self, message):
"""Respond with a message."""
# stop immediately if the message is from the bot itself.
if message.user == self.github_username:
return True
_LOGGER.debug(_("Responding via GitHub."))
repo, issue = message.target.split("#")
url = "{}/repos/{}/issues/{}/comments".format(GITHUB_API_URL, repo, issue)
headers = {"Authorization": " token {}".format(self.github_token)}
async with aiohttp.ClientSession(trust_env=True) as session:
resp = await session.post(url, json={"body": message.text}, headers=headers)
if resp.status == 201:
_LOGGER.info(_("Message sent."))
return True
_LOGGER.error(await resp.json())
return False
@register_event(Message)
async def send_message(self, message):
"""Respond with a message."""
_LOGGER.debug(
_("Responding with: '%s' in room %s."), message.text, message.target
)
await self.slack.api_call(
"chat.postMessage",
data={
"channel": message.target,
"text": message.text,
"as_user": self.chat_as_user,
"username": self.bot_name,
"icon_emoji": self.icon_emoji,
},
@register_event(Message)
async def send_message(self, message):
"""Recived parsed message and send it back to gitter room."""
# Send message.text back to the chat service
url = self.build_url(GITTER_MESSAGE_BASE_API, message.target, "chatMessages")
headers = {
"Authorization": "Bearer " + self.access_token,
"Content-Type": "application/json",
"Accept": "application/json",
}
payload = {"text": message.text}
resp = await self.session.post(url, json=payload, headers=headers)
if resp.status == 200:
_LOGGER.info(_("Successfully responded."))
else:
_LOGGER.error(_("Unable to respond."))
@register_event(matrixevents.MatrixStateEvent, include_subclasses=True)
@ensure_room_id_and_send
async def _send_state_event(self, state_event):
_LOGGER.debug(f"Sending State Event {state_event}")
return await self.connection.send_state_event(
state_event.target,
state_event.key,
state_event.content,
state_key=state_event.state_key,
)
@register_event(events.JoinRoom)
@ensure_room_id_and_send
async def _send_join_room(self, join_event):
return await self.connection.join_room(join_event.target)
@register_event(events.RoomName)
@ensure_room_id_and_send
async def _send_room_name_set(self, name_event):
return await self.connection.set_room_name(name_event.target, name_event.name)
@register_event(Message)
async def respond(self, message):
"""Respond with a message.
Args:
message (object): An instance of Message
"""
_LOGGER.debug(_("Responding with: %s."), message.text)
self.clear_prompt()
print(message.text)
self.draw_prompt()
@register_event(events.RoomDescription)
@ensure_room_id_and_send
async def _send_room_desciption(self, desc_event):
return await self.connection.set_room_topic(
desc_event.target, desc_event.description
)