async def run_timed_votds(bot): await bot.wait_until_ready() current_time = datetime.datetime.utcnow().strftime("%H:%M") async with aiotinydb.AIOTinyDB(central.guildDB_path) as guildDB: results = [ x for x in guildDB.all() if "channel" in x and x["time"] == current_time ] count = 0 for item in results: if "channel" in item and "time" in item: channel = bot.get_channel(item["channel"]) try: version = await versions.get_guild_version(channel.guild) lang = await languages.get_guild_language(channel.guild) except AttributeError: version = "RSV" lang = "english" if not version: version = "RSV" if not lang: lang = "english" lang = central.get_raw_language(lang) if channel: reference = await bibleutils.get_votd() result = await utils.get_bible_verse( reference, "embed", version, "enable", "enable") if result: try: await channel.send(lang["votd"]) await channel.send(embed=result["embed"]) except discord.errors.Forbidden: pass count += 1 if count > 0: central.log_message( "info", 0, "votd_sched", "global", f"Sending {str(count)} VOTDs at {current_time}...")
async def run_timed_votds(self): await self.wait_until_ready() while not self.is_closed(): current_time = datetime.datetime.utcnow().strftime("%H:%M") results = [ x for x in central.guildDB.all() if "channel" in x and x["time"] == current_time ] for item in results: if "channel" in item and "time" in item: channel = self.get_channel(item["channel"]) try: version = versions.get_guild_version(channel.guild) lang = languages.get_guild_language(channel.guild) except AttributeError: version = "RSV" lang = "english" if not lang: lang = "english" lang = central.get_raw_language(lang) await channel.send(lang["votd"]) reference = await bibleutils.get_votd() # noinspection PyBroadException try: result = await utils.get_bible_verse( reference, "embed", version, "enable", "enable") await channel.send(embed=result["embed"]) except Exception: traceback.print_exc() pass central.log_message("info", 0, "votd_sched", "global", f"Sending VOTDs at {current_time}...") await asyncio.sleep(60)
async def run_command(ctx, command, remainder): lang = ctx["language"] user = ctx["author"] guild = ctx["guild"] channel = ctx["channel"] args = remainder.split(" ") if command == "biblebot": pages = biblebot.create_biblebot_embeds(lang) return { "level": "info", "paged": True, "pages": pages } elif command == "search": version = utils.get_version(user, guild) return await paged_commands.search(version, remainder, lang) elif command == "versions": return paged_commands.get_versions(lang) elif command == "setversion": if versions.set_version(user, args[0]): embed = utils.create_embed(lang["commands"]["setversion"], lang["setversionsuccess"]) return { "level": "info", "message": embed } else: embed = utils.create_embed(lang["commands"]["setversion"], lang["setversionfail"].replace("<versions>", lang["commands"]["versions"]), error=True) return { "level": "err", "message": embed } elif command == "setguildversion": perms = user.guild_permissions if not perms: embed = utils.create_embed(lang["commands"]["setguildversion"], lang["setguildversionnoperm"], error=True) return { "level": "err", "message": embed } if str(user.id) != central.config["BibleBot"]["owner"]: if not perms.manage_guild: embed = utils.create_embed(lang["commands"]["setguildversion"], lang["setguildversionnoperm"], error=True) return { "level": "err", "message": embed } if versions.set_guild_version(guild, args[0]): embed = utils.create_embed(lang["commands"]["setguildversion"], lang["setguildversionsuccess"]) return { "level": "info", "message": embed } else: embed = utils.create_embed(lang["commands"]["setguildversion"], lang["setguildversionfail"].replace("<versions>", lang["commands"]["versions"]), error=True) return { "level": "err", "message": embed } elif command == "version": version = versions.get_version(user) if version is not None: response = lang["versionused"] response = response.replace("<version>", version) response = response.replace("<setversion>", lang["commands"]["setversion"]) embed = utils.create_embed(lang["commands"]["version"], response) return { "level": "info", "message": embed } else: response = lang["noversionused"] response = response.replace("<setversion>", lang["commands"]["setversion"]) embed = utils.create_embed(lang["commands"]["version"], response, error=True) return { "level": "err", "message": embed } elif command == "guildversion": version = versions.get_guild_version(guild) if version is not None: response = lang["guildversionused"] response = response.replace("<version>", version) response = response.replace("<setguildversion>", lang["commands"]["setguildversion"]) embed = utils.create_embed(lang["commands"]["guildversion"], response) return { "level": "info", "message": embed } else: response = lang["noguildversionused"] response = response.replace("<setguildversion>", lang["commands"]["setguildversion"]) embed = utils.create_embed(lang["commands"]["guildversion"], response, error=True) return { "level": "err", "message": embed } elif command == "versioninfo": ideal_version = tinydb.Query() results = central.versionDB.search(ideal_version["abbv"] == args[0]) if len(results) > 0: response = lang["versioninfo"] response = response.replace("<versionname>", results[0]["name"]) def check_validity(section): if results[0]["has" + section]: return lang["arguments"]["yes"] else: return lang["arguments"]["no"] for category in ["OT", "NT", "DEU"]: response = response.replace(f"<has{category}>", check_validity(category)) embed = utils.create_embed(lang["commands"]["versioninfo"], response) return { "level": "info", "message": embed } else: embed = utils.create_embed(lang["commands"]["versioninfo"], lang["versioninfofailed"], error=True) return { "level": "err", "message": embed } elif command == "setlanguage": if languages.set_language(user, args[0]): embed = utils.create_embed(lang["commands"]["setlanguage"], lang["setlanguagesuccess"]) return { "level": "info", "message": embed } else: embed = utils.create_embed(lang["commands"]["setlanguage"], lang["setlanguagefail"].replace("<languages>", lang["commands"]["languages"]), error=True) return { "level": "err", "message": embed } elif command == "setguildlanguage": perms = user.guild_permissions if not perms: embed = utils.create_embed(lang["commands"]["setguildlanguage"], lang["setguildlanguagenoperm"], error=True) return { "level": "err", "message": embed } if str(user.id) != central.config["BibleBot"]["owner"]: if not perms.manage_guild: embed = utils.create_embed(lang["commands"]["setguildlanguage"], lang["setguildlanguagenoperm"], error=True) return { "level": "err", "message": embed } if languages.set_guild_language(guild, args[0]): embed = utils.create_embed(lang["commands"]["setguildlanguage"], lang["setguildlanguagesuccess"]) return { "level": "info", "message": embed } else: description = lang["setguildlanguagefail"].replace("<languages>", lang["commands"]["languages"]) embed = utils.create_embed(lang["commands"]["setguildlanguage"], description, error=True) return { "level": "err", "message": embed } elif command == "language": response = lang["languageused"] response = response.replace("<setlanguage>", lang["commands"]["setlanguage"]) embed = utils.create_embed(lang["commands"]["language"], response) return { "level": "info", "message": embed } elif command == "guildlanguage": glang = languages.get_guild_language(guild) glang = central.get_raw_language(glang) response = glang["guildlanguageused"] response = response.replace("<setguildlanguage>", glang["commands"]["setguildlanguage"]) embed = utils.create_embed(glang["commands"]["guildlanguage"], response) return { "level": "info", "message": embed } elif command == "languages": available_languages = languages.get_languages() string = "" for item in available_languages: if item["object_name"] != "default": string += item["name"] + " [`" + item["object_name"] + "`]\n" embed = utils.create_embed(lang["commands"]["languages"], string) return { "level": "info", "message": embed } elif command == "setguildbrackets": perms = user.guild_permissions if not perms: embed = utils.create_embed(lang["commands"]["setguildbrackets"], lang["setguildbracketsnoperm"], error=True) return { "level": "err", "message": embed } if str(user.id) != central.config["BibleBot"]["owner"]: if not perms.manage_guild: embed = utils.create_embed(lang["commands"]["setguildbrackets"], lang["setguildbracketsnoperm"], error=True) return { "level": "err", "message": embed } if formatting.set_guild_brackets(guild, args[0]): embed = utils.create_embed(lang["commands"]["setguildbrackets"], lang["setguildbracketssuccess"]) return { "level": "info", "message": embed } else: embed = utils.create_embed(lang["commands"]["setguildbrackets"], lang["setguildbracketsfail"], error=True) return { "level": "err", "message": embed } elif command == "guildbrackets": brackets_dict = formatting.get_guild_brackets(guild) brackets = brackets_dict["first"] + brackets_dict["second"] response = lang["guildbracketsused"] response = response.replace("<brackets>", brackets) response = response.replace("<setguildbrackets>", lang["commands"]["setguildbrackets"]) embed = utils.create_embed(lang["commands"]["guildbrackets"], response) return { "level": "info", "message": embed } elif command == "setvotdtime": perms = user.guild_permissions if not perms: embed = utils.create_embed(lang["commands"]["setvotdtime"], lang["setvotdtimenoperm"], error=True) return { "level": "err", "message": embed } if str(user.id) != central.config["BibleBot"]["owner"]: if not perms.manage_guild: embed = utils.create_embed(lang["commands"]["setvotdtime"], lang["setvotdtimenoperm"], error=True) return { "level": "err", "message": embed } if misc.set_guild_votd_time(guild, channel, args[0]): embed = utils.create_embed(lang["commands"]["setvotdtime"], lang["setvotdtimesuccess"]) return { "level": "info", "message": embed } else: embed = utils.create_embed(lang["commands"]["setvotdtime"], lang["setvotdtimefail"], error=True) return { "level": "err", "message": embed } elif command == "clearvotdtime": perms = user.guild_permissions if not perms: embed = utils.create_embed(lang["commands"]["clearvotdtime"], lang["clearvotdtimenoperm"], error=True) return { "level": "err", "message": embed } if str(user.id) != central.config["BibleBot"]["owner"]: if not perms.manage_guild: embed = utils.create_embed(lang["commands"]["clearvotdtime"], lang["clearvotdtimenoperm"], error=True) return { "level": "err", "message": embed } if misc.set_guild_votd_time(guild, channel, "clear"): embed = utils.create_embed(lang["commands"]["clearvotdtime"], lang["clearvotdtimesuccess"]) return { "level": "info", "message": embed } elif command == "votdtime": time_tuple = misc.get_guild_votd_time(guild) if time_tuple is not None: channel, time = time_tuple response = lang["votdtimeused"] response = response.replace("<time>", time + " UTC") response = response.replace("<channel>", channel) response = response.replace("<setvotdtime>", lang["commands"]["setvotdtime"]) response = response.replace("<clearvotdtime>", lang["commands"]["clearvotdtime"]) embed = utils.create_embed(lang["commands"]["votdtime"], response) return { "level": "info", "message": embed } else: response = lang["novotdtimeused"] response = response.replace("<setvotdtime>", lang["commands"]["setvotdtime"]) embed = utils.create_embed(lang["commands"]["votdtime"], response, error=True) return { "level": "err", "message": embed } elif command in ["votd", "verseoftheday"]: verse = await bibleutils.get_votd() mode = formatting.get_mode(user) version = utils.get_version(user, guild) headings = formatting.get_headings(user) verse_numbers = formatting.get_verse_numbers(user) return await utils.get_bible_verse(verse, mode, version, headings, verse_numbers) elif command == "random": verse = await bibleutils.get_random_verse() mode = formatting.get_mode(user) version = utils.get_version(user, guild) headings = formatting.get_headings(user) verse_numbers = formatting.get_verse_numbers(user) return await utils.get_bible_verse(verse, mode, version, headings, verse_numbers) elif command == "setheadings": if formatting.set_headings(user, args[0]): embed = utils.create_embed(lang["commands"]["setheadings"], lang["headingssuccess"]) return { "level": "info", "message": embed } else: response = lang["headingsfail"] response = response.replace("<setheadings>", lang["commands"]["setheadings"]) response = response.replace("<enable>", lang["arguments"]["enable"]) response = response.replace("<disable>", lang["arguments"]["disable"]) embed = utils.create_embed(lang["commands"]["setheadings"], response, error=True) return { "level": "err", "message": embed } elif command == "headings": headings = formatting.get_headings(user) if headings == "enable": response = lang["headings"].replace("<enabled/disabled>", lang["enabled"]) response = response.replace("<setheadings>", lang["commands"]["setheadings"]) embed = utils.create_embed(lang["commands"]["headings"], response) return { "level": "info", "message": embed } else: response = lang["headings"].replace("<enabled/disabled>", lang["disabled"]) response = response.replace("<setheadings>", lang["commands"]["setheadings"]) embed = utils.create_embed(lang["commands"]["headings"], response) return { "level": "info", "message": embed } elif command == "setmode": if formatting.set_mode(user, args[0]): embed = utils.create_embed(lang["commands"]["setmode"], lang["modesuccess"]) return { "level": "info", "message": embed } else: response = lang["modefail"] response = response.replace("<setmode>", lang["commands"]["setmode"]) embed = utils.create_embed(lang["commands"]["setmode"], response, error=True) return { "level": "err", "message": embed } elif command == "mode": mode = formatting.get_mode(user) modes = ["default", "embed", "blockquote", "code"] if mode in modes: response = lang["mode"].replace("<value>", mode) response = response.replace("<setmode>", lang["commands"]["setmode"]) embed = utils.create_embed(lang["commands"]["mode"], response) return { "level": "info", "message": embed } elif command == "setversenumbers": if formatting.set_verse_numbers(user, args[0]): embed = utils.create_embed(lang["commands"]["setversenumbers"], lang["versenumberssuccess"]) return { "level": "info", "message": embed } else: response = lang["versenumbersfail"].replace("<setversenumbers>", lang["commands"]["setversenumbers"]) response = response.replace("<enable>", lang["arguments"]["enable"]) response = response.replace("<disable>", lang["arguments"]["disable"]) embed = utils.create_embed(lang["commands"]["setversenumbers"], response, error=True) return { "level": "err", "message": embed } elif command == "versenumbers": verse_numbers = formatting.get_verse_numbers(user) response = lang["versenumbers"].replace("<setversenumbers>", lang["commands"]["setversenumbers"]) if verse_numbers == "enable": response = response.replace("<enabled/disabled>", lang["enabled"]) else: response = response.replace("<enabled/disabled>", lang["disabled"]) embed = utils.create_embed(lang["commands"]["versenumbers"], response) return { "level": "info", "message": embed } elif command == "setannouncements": perms = user.guild_permissions if not perms: embed = utils.create_embed(lang["commands"]["setannouncements"], lang["setannouncementsnoperm"], error=True) return { "level": "err", "message": embed } if not perms.manage_guild: embed = utils.create_embed(lang["commands"]["setannouncements"], lang["setannouncementsnoperm"], error=True) return { "level": "err", "message": embed } if misc.set_guild_announcements(guild, channel, args[0]): embed = utils.create_embed(lang["commands"]["setannouncements"], lang["setannouncementssuccess"]) return { "level": "info", "message": embed } else: response = lang["setannouncementsfail"] response = response.replace("<setannouncements>", lang["commands"]["setannouncements"]) response = response.replace("<enable>", lang["arguments"]["enable"]) response = response.replace("<disable>", lang["arguments"]["disable"]) embed = utils.create_embed(lang["commands"]["setannouncements"], response, error=True) return { "level": "err", "message": embed } elif command == "announcements": announce_tuple = misc.get_guild_announcements(guild, True) if announce_tuple is not None: channel, setting = announce_tuple if setting: response = lang["announcementsenabled"] else: response = lang["announcementsdisabled"] response = response.replace("<channel>", channel) response = response.replace("<setannouncements>", lang["commands"]["setannouncements"]) embed = utils.create_embed(lang["commands"]["announcements"], response) return { "level": "info", "message": embed } else: response = lang["noannouncements"] response = response.replace("<setannouncements>", lang["commands"]["setannouncements"]) embed = utils.create_embed(lang["commands"]["announcements"], response, error=True) return { "level": "err", "message": embed } elif command == "users": processed = len(ctx["self"].users) embed = utils.create_embed(lang["commands"]["users"], lang["users"] + ": " + str(processed)) return { "level": "info", "message": embed } elif command == "servers": processed = len(ctx["self"].guilds) embed = utils.create_embed(lang["commands"]["servers"], lang["servers"].replace("<count>", str(processed))) return { "level": "info", "message": embed } elif command == "jepekula": version = utils.get_version(user, guild) mode = formatting.get_mode(user) headings = formatting.get_headings(user) verse_numbers = formatting.get_verse_numbers(user) return await utils.get_bible_verse("Mark 9:23-24", mode, version, headings, verse_numbers) elif command in special.cm_commands: return special.get_custom_message(command) elif command == "supporters": return special.get_supporters(lang) elif command == "creeds": return creeds.get_creeds(lang) elif command in creeds.creeds: return creeds.get_creed(command, lang) elif command == "catechisms": return catechisms.get_catechisms(lang) elif command == "invite": bot_id = ctx["self"].user.id return { "level": "info", "text": True, "message": f"https://discordapp.com/oauth2/authorize?client_id={bot_id}&scope=bot&permissions=93248" }
async def on_message(self, raw): owner_id = config["BibleBot"]["owner"] await self.wait_until_ready() if ":" not in raw.content: if config["BibleBot"]["commandPrefix"] not in raw.content: return ctx = { "self": bot, "author": raw.author, "identifier": f"{raw.author.id}", "channel": raw.channel, "message": raw.content, "raw": raw, "guild": None, "language": None } is_self = ctx["author"] == self.user is_optout = central.is_optout(str(ctx["author"].id)) if is_self or is_optout: return is_owner = ctx["identifier"] == owner_id if is_owner: ctx["identifier"] = "owner" language = languages.get_language(ctx["author"]) if hasattr(ctx["channel"], "guild"): ctx["guild"] = ctx["channel"].guild if language is None: language = languages.get_guild_language(ctx["guild"]) guild_id = str(ctx["channel"].guild.id) chan_id = str(ctx["channel"].id) source = f"{guild_id}#{chan_id}" if "Discord Bot" in ctx["channel"].guild.name: if not is_owner: return else: source = "unknown (direct messages?)" if ctx["guild"] is None: shard = 1 else: shard = ctx["guild"].shard_id + 1 if language is None or language in ["english_us", "english_uk"]: language = "english" if config["BibleBot"]["devMode"] == "True": # more often than not, new things are added that aren't filtered # through crowdin yet so we do this to avoid having to deal with # missing values language = "default" if not is_owner: return ctx["language"] = central.get_raw_language(language) if ctx["message"].startswith(config["BibleBot"]["commandPrefix"]): command = ctx["message"][1:].split(" ")[0] remainder = " ".join(ctx["message"].split(" ")[1:]) cmd_handler = CommandHandler() res = await cmd_handler.process_command(ctx, command, remainder) original_command = "" if res is None: return if "announcement" in res: central.log_message("info", 0, "owner", "global", "Announcement starting.") await bot_extensions.send_announcement(ctx, res) central.log_message("info", 0, "owner", "global", "Announcement finished.") return if "isError" not in res: if "twoMessages" in res: await ctx["channel"].send(res["firstMessage"]) await ctx["channel"].send(res["secondMessage"]) elif "paged" in res: msg = await ctx["channel"].send(embed=res["pages"][0]) self.current_page[msg.id] = 1 self.total_pages[msg.id] = len(res["pages"]) await msg.add_reaction("⬅") await msg.add_reaction("➡") def check(r, u): if r.message.id == msg.id: if str(r.emoji) == "⬅": if u.id != bot.user.id: if self.current_page[msg.id] != 1: self.current_page[msg.id] -= 1 return True elif str(r.emoji) == "➡": if u.id != bot.user.id: if self.current_page[ msg.id] != self.total_pages[ msg.id]: self.current_page[msg.id] += 1 return True self.continue_paging[msg.id] = True try: while self.continue_paging[msg.id]: reaction, _ = await asyncio.ensure_future( bot.wait_for('reaction_add', timeout=60.0, check=check)) await reaction.message.edit( embed=res["pages"][self.current_page[msg.id] - 1]) reaction, _ = await asyncio.ensure_future( bot.wait_for('reaction_remove', timeout=60.0, check=check)) await reaction.message.edit( embed=res["pages"][self.current_page[msg.id] - 1]) except (asyncio.TimeoutError, IndexError): try: self.current_page.pop(msg.id) self.total_pages.pop(msg.id) self.continue_paging.pop(msg.id) await msg.clear_reactions() except (discord.errors.Forbidden, discord.errors.NotFound): pass elif "embed" in res: try: await ctx["channel"].send(embed=res["embed"]) except discord.errors.Forbidden: await ctx["channel"].send( "Unable to send embed, please verify permissions.") else: if "reference" not in res and "text" not in res: await ctx["channel"].send(embed=res["message"]) else: await ctx["channel"].send(res["message"]) lang = central.get_raw_language(language) for original_command_name in lang["commands"].keys(): untranslated = [ "setlanguage", "userid", "ban", "unban", "reason", "optout", "unoptout", "eval", "jepekula", "joseph", "tiger", "rose", "lsc", "heidelberg", "ccc", "quit" ] if lang["commands"][original_command_name] == command: original_command = original_command_name elif command in untranslated: original_command = command clean_args = remainder.replace("\"", "").replace("'", "").replace( " ", " ") clean_args = clean_args.replace("\n", "").strip() ignore_arg_commands = ["puppet", "eval", "announce"] if original_command in ignore_arg_commands: clean_args = "" central.log_message(res["level"], shard, ctx["identifier"], source, f"+{original_command} {clean_args}") else: await ctx["channel"].send(embed=res["message"]) else: verse_handler = VerseHandler() result = await verse_handler.process_raw_message( raw, ctx["author"], ctx["language"], ctx["guild"]) if result is not None: if "invalid" not in result and "spam" not in result: for item in result: try: if "twoMessages" in item: await ctx["channel"].send(item["firstMessage"]) await ctx["channel"].send(item["secondMessage"] ) elif "message" in item: await ctx["channel"].send(item["message"]) elif "embed" in item: await ctx["channel"].send(embed=item["embed"]) if "reference" in item: central.log_message(item["level"], shard, ctx["identifier"], source, item["reference"]) except (KeyError, TypeError): pass elif "spam" in result: central.log_message("warn", shard, ctx["identifier"], source, "Too many verses at once.") await ctx["channel"].send(result["spam"])