Example #1
0
async def on_message(message):
    if message.author == bot.user:
        return
    if message.author.bot:
        return

    await bot.process_commands(message)

    if message.type != discord.MessageType.default:
        return

    chat_config = get_chat_config(message.guild, message.channel)
    if chat_config.lock: return

    msg = message.content
    if len(msg) == 0:
        logger.debug("OOPS, zero-length message...")
        logger.debug(message)
        return
    msgtr = common.process_message(
        msg, chat_config.tabs, config.min_levenshtein_ratio,
        "[TEST MODE] " if config.test_mode else False)
    if msgtr:
        em = discord.Embed(description=msgtr)
        await message.channel.send(embed=em)
Example #2
0
def translate_message(message):
  msg = message.text
  print ("%s|%s <%s %s> %s" % (str(message.chat.id), strftime("%Y-%m-%d %H:%M:%S", localtime(message.date)), message.from_user.first_name, message.from_user.last_name, msg))
  chat_config = get_chat_config(message.chat)
  if "via_bot" in message.json and message.json["via_bot"]["username"] in config.blacklist_inline_bots:
    if chat_config.inline_policy == 2:
      print (f" inline bot {message.json['via_bot']['username']} blacklisted")
      try:
        bot.delete_message(message.chat.id, message.message_id)
      except telebot.apihelper.ApiException:
        print (f" delete failed")
      return
    elif chat_config.inline_policy == 1:
      return
  if chat_config.lock: return
  if time() > message.date+config.max_timediff:
    print (" message time too old :(")
    return
  msgtr = common.process_message(msg, chat_config.tabs, config.min_levenshtein_ratio, "[TEST MODE] " if config.test_mode else False)
  if msgtr:
    try:
      bot.send_message(message.chat.id, msgtr, reply_to_message_id=message.message_id)
    except telebot.apihelper.ApiException:
      print (" Exception occured!")
  return
Example #3
0
 async def on_message(self, room: MatrixRoom,
                      event: RoomMessageText) -> None:
     if event.sender == self.client.user_id:
         return
     print(
         f"{strftime('%Y-%m-%d %H:%M:%S', localtime(event.server_timestamp/1000))}: {room.room_id}({room.display_name})|<{event.sender}({room.user_name(event.sender)})> {event.body}"
     )
     if time() - event.server_timestamp / 1000 > config.max_timediff:
         print(" ` skip old message")
         return
     msg = event.body
     msgtr = common.process_message(
         msg, config.default_tabs, config.min_levenshtein_ratio,
         "[TEST MODE] " if config.test_mode else False)
     if msgtr:
         content = {
             "msgtype": "m.text",
             "body": msgtr,
         }
         m_relates_to = event.source["content"].get("m.relates_to", None)
         if m_relates_to and m_relates_to.get("rel_type",
                                              None) == "io.element.thread":
             content["m.relates_to"] = {
                 "rel_type": "io.element.thread",
                 "event_id": m_relates_to.get("event_id", None),
             }
         await self.client.room_send(
             room_id=room.room_id,
             message_type="m.room.message",
             content=content,
             ignore_unverified_devices=True,
         )
Example #4
0
import os

import boto3

from common import SignalHandler, process_message, queue_length

sqs = boto3.resource("sqs")
dlq = sqs.get_queue_by_name(QueueName=os.environ["SQS_DEAD_LETTER_QUEUE_NAME"])

if __name__ == "__main__":
    signal_handler = SignalHandler()
    while queue_length(dlq) and not signal_handler.received_signal:
        print(f"queue length: {queue_length(dlq)}")
        messages = dlq.receive_messages(
            MaxNumberOfMessages=10,
            WaitTimeSeconds=1,
        )
        for message in messages:
            process_message(message.body)
            message.delete()