def set_reminder( self, channel, author, content: str, tim: int, lang: str, reminder_type: Union[REMINDER_CHANNEL, REMINDER_PERSONAL] = REMINDER_PERSONAL): """ Sets a reminder :param channel: Where to send this :param author: Who is the author :param content: String : message :param tim: time (int) :param reminder_type: type of reminder (personal (DM) or channel) :param lang: language used in that guild :return: bool indicating success """ t = time.time() if not self.can_add_reminders(author.id): return -1 if not (REM_MIN_DURATION <= tim < REM_MAX_DURATION ): # Allowed reminder duration: 5 sec to 2 days return False raw = str(content) # Add the reminder to the list rm_id = gen_id(length=12) if reminder_type == REMINDER_PERSONAL: tree = { "receiver": author.id, "time_created": int(t), "author": author.id, "lang": lang, "time_target": int(tim + t), "raw": raw, "type": reminder_type } else: tree = { "receiver": channel.id, "server": channel.guild.id, "author": author.id, "lang": lang, "time_created": int(t), "time_target": int(tim + t), "raw": raw, "type": reminder_type } log.info("New reminder by {}".format(author.id)) hash_name = "{}:{}".format(author.id, rm_id) return self.redis.hmset(hash_name, tree)
async def on_message(self, message, **kwargs): trans = self.trans prefix = kwargs.get("prefix") lang = kwargs.get("lang") simple_commands = {"( ͡° ͜ʖ ͡°)": trans.get("MSG_WHOKNOWS", lang)} # Loop over simple commands for k, v in simple_commands.items(): if message.content.startswith(k): await message.channel.send(v) self.stats.add(MESSAGE) return # Check if this is a valid command if not is_valid_command(message.content, commands, prefix): return else: self.stats.add(MESSAGE) def startswith(*matches): for match in matches: if message.content.startswith(match): return True return False # Other commands if startswith(prefix + "kappa"): await message.channel.send(file=File(KAPPA_LOCATION, "kappa.png")) self.stats.add(IMAGE_SENT) # !randomgif (optional_tag) elif startswith(prefix + "randomgif"): tags = message.content[len(prefix + "randomgif "):] gif = await self.gif.get_random_gif(tags or None) nonexistent = False if gif == -1: await message.channel.send(trans.get("MSG_GIPHY_TOOFAST", lang)) return # Gif with such tag does not exist, fall back to random one if gif is None: gif = await self.gif.get_random_gif() nonexistent = True embed = Embed(colour=Colour(GIPHY_GREEN)) embed.set_image(url=gif) if not nonexistent: embed.set_footer(text=trans.get("MSG_GIPHY_POWEREDBY", lang)) else: that_text = trans.get( "MSG_GIPHY_POWEREDBY", lang) + " | " + trans.get( "MSG_GIPHY_NOSUCHTAG", lang).format(add_dots(tags, 20)) embed.set_footer(text=that_text) await message.channel.send(embed=embed) self.stats.add(IMAGE_SENT) # !meme [meme name]|[top text]|[bottom text] elif startswith(prefix + "meme"): query = message.content[len(prefix + "meme "):] if not query: await message.channel.send( trans.get("ERROR_INVALID_CMD_ARGUMENTS", lang)) return middle = [a.strip(" ") for a in query.split("|")] # If only two arguments are passed, assume no bottom text if len(middle) == 2: name = middle[0] top = middle[1] bottom = "" # 0, 1 or more than 3 arguments - error elif len(middle) < 2 or len(middle) > 3: await message.channel.send( trans.get("MSG_MEME_USAGE", lang).replace("_", prefix)) return # Normal else: name = middle[0] top = middle[1] bottom = middle[2] meme = await self.generator.caption_meme(name, top, bottom) if not meme: await message.channel.send( trans.get("MSG_MEME_NONEXISTENT", lang)) else: embed = Embed(colour=Colour(0x607D8B)) embed.set_image(url=meme) embed.set_footer(text=trans.get("MSG_MEME_FOOTER", lang)) await message.channel.send(embed=embed) elif startswith(prefix + "rip"): if len(message.mentions) == 1: ripperoni = " " + message.mentions[0].name elif len(message.mentions) == 0: ripperoni = " " + message.content[len(prefix + "rip "):] else: ripperoni = "" ripperoni = self.everyone_filter(ripperoni, message.author, force_remove=True) prays = self.stats.get_amount(PRAYER) await message.channel.send( trans.get("MSG_RIP", lang).format(ripperoni, prays)) self.stats.add(PRAYER) elif startswith(prefix + "achievement"): text = message.content[len(prefix + "achievement "):].strip(" ") if not text: await message.channel.send( trans.get("MSG_ACHIEVMENT_NOTEXT", lang)) return img = self.achievement.create_image(text) img_filename = "Achievement_{}.png".format(gen_id(4)) await message.channel.send(file=File(img, img_filename)) # Just in case GC fails del img