async def anime(self, ctx, *, name: str): """Searches MyAnimeList for the specified anime""" await ctx.channel.trigger_typing() r = requests.get( "https://myanimelist.net/api/anime/search.xml?q={}".format(name), auth=requests.auth.HTTPBasicAuth(config._malUsername, config._malPassword)) if r.status_code == 401: log.critical( "The MyAnimeList credinals are incorrect, please check your MyAnimeList login information in the config." ) await ctx.send(Language.get("myanimelist.incorrect_creds", ctx)) return try: xmldoc = minidom.parseString(r.text) except XmlParserErrors.ExpatError: await ctx.send( Language.get("myanimelist.no_anime_found", ctx).format(name)) return # pls no flame anime = xmldoc.getElementsByTagName("entry")[0] id = anime.getElementsByTagName("id")[0].firstChild.nodeValue title = anime.getElementsByTagName("title")[0].firstChild.nodeValue try: english = anime.getElementsByTagName( "english")[0].firstChild.nodeValue except: english = title episodes = anime.getElementsByTagName( "episodes")[0].firstChild.nodeValue score = anime.getElementsByTagName("score")[0].firstChild.nodeValue type = anime.getElementsByTagName("type")[0].firstChild.nodeValue status = anime.getElementsByTagName("status")[0].firstChild.nodeValue start_date = anime.getElementsByTagName( "start_date")[0].firstChild.nodeValue end_date = anime.getElementsByTagName( "end_date")[0].firstChild.nodeValue image = anime.getElementsByTagName("image")[0].firstChild.nodeValue synopsis = saxutils.unescape( anime.getElementsByTagName("synopsis")[0].firstChild.nodeValue) synopsis = remove_html(synopsis) if len(synopsis) > 300: synopsis = synopsis[:300] + "..." url = "https://myanimelist.net/anime/{}".format(id) fields = { Language.get("myanimelist.english_title", ctx): english, Language.get("myanimelist.episodes", ctx): episodes, Language.get("myanimelist.mal_line", ctx): score, Language.get("myanimelist.type", ctx): type, Language.get("myanimelist.status", ctx): status, Language.get("myanimelist.start_date", ctx): start_date, Language.get("myanimelist.end_date", ctx): end_date } embed = make_list_embed(fields) embed.title = title embed.description = synopsis embed.url = url embed.color = 0xFF0000 embed.set_thumbnail(url=image) await ctx.send(embed=embed)
async def set_default_status(): if not config.enable_default_status: return type = config.default_status_type name = config.default_status_name try: type = discord.Status(type) except: type = discord.Status.online if name is not None: if config.default_status_type == "stream": if config.default_status_name is None: log.critical( "If the status type is set to \"stream\" then the default status game must be specified" ) os._exit(1) status = discord.Activity(name=name, url="http://twitch.tv/ZeroEpoch1969", type=discord.ActivityType.streaming) else: status = discord.Activity(name=name, type=discord.ActivityType.playing) await bot.change_presence(status=type, activity=status) else: await bot.change_presence(status=type)
async def set_default_status(): if not config.enable_default_status: return type = config.default_status_type game = config.default_status_name try: type = discord.Status(type) except: type = discord.Status.online if game is not None: if config.default_status_type == "stream": if config.default_status_name is None: log.critical( "If the status type is set to \"stream\" then the default status game must be specified" ) os._exit(1) game = discord.Activity(name=game, url="http://twitch.tv/robingall2910", type=discord.ActivityType.streaming) else: game = discord.Activity( #name="New command invokes are now available!\n\"hey derg\", \"hey dragon\", \"hey batzz\", and \"r.\"! \n\n#BetoSanders2020 #AbramsForGovernor", type=discord.ActivityType.playing) name="happy pride month (blm!)", type=discord.ActivityType.playing) # pyrawanpmjadbapanwmjamtsatltsadw await bot.change_presence(status=type, activity=game) else: await bot.change_presence(status=type)
async def manga(self, ctx, *, name:str): """Searches MyAnimeList for the specified manga""" await self.bot.send_typing(ctx.message.channel) r = requests.get("https://myanimelist.net/api/manga/search.xml?q={}".format(name), auth=requests.auth.HTTPBasicAuth(config._malUsername, config._malPassword)) if r.status_code == 401: log.critical("The MyAnimeList credinals are incorrect, please check your MyAnimeList login information in the config.") await self.bot.say("The MyAnimeList credinals are incorrect, contact the bot developer!") return with open("data/manga.xml", "wb") as xml: xml.write(r.content) try: xmldoc = minidom.parse("data/manga.xml") except XmlParserErrors.ExpatError: await self.bot.say("Couldn't find any manga named `{}`".format(name)) return # pls no flame anime = xmldoc.getElementsByTagName("entry")[0] id = anime.getElementsByTagName("id")[0].firstChild.nodeValue title = anime.getElementsByTagName("title")[0].firstChild.nodeValue try: english = anime.getElementsByTagName("english")[0].firstChild.nodeValue except: english = title chapters = anime.getElementsByTagName("chapters")[0].firstChild.nodeValue volumes = anime.getElementsByTagName("volumes")[0].firstChild.nodeValue score = anime.getElementsByTagName("score")[0].firstChild.nodeValue type = anime.getElementsByTagName("type")[0].firstChild.nodeValue status = anime.getElementsByTagName("status")[0].firstChild.nodeValue start_date = anime.getElementsByTagName("start_date")[0].firstChild.nodeValue end_date = anime.getElementsByTagName("end_date")[0].firstChild.nodeValue url = "https://myanimelist.net/manga/{}".format(id) msg = "```Title: {}\nEnglish title: {}\nChapters: {}\nVolumes: {}\nScore: {}\nType: {}\nStatus: {}\nStart date: {}\nEnd Date: {}```\nRead more: {}".format(title, english, chapters, volumes, score, type, status, start_date, end_date, url) await self.bot.say(msg)
async def set_default_status(): if not config.enable_default_status: return type = config.default_status_type game = config.default_status_name try: type = discord.Status(type) except: type = discord.Status.online if game is not None: if config.default_status_type == "stream": if config.default_status_name is None: log.critical( "If the status type is set to \"stream\" then the default status game must be specified" ) os._exit(1) game = discord.Game(name=game, url="http://twitch.tv/robingall2910", type=1) else: game = discord.Game( name="Shard {} of {} // {} guilds on this shard".format( str(shard_id), str(shard_count), len(bot.servers))) await bot.change_presence(status=type, game=game) else: await bot.change_presence(status=type)
def run_checks(): if not os.path.isdir("data"): log.warning('No folder named "data" was found, creating one... (This message is harmless)') os.makedirs("data") if not os.path.isdir("assets"): log.critical( 'There is no folder named "assets"! Please go to the github repo and download the assets folder!' ) os._exit(1)
def run_checks(): if not os.path.isdir("data"): log.warning( "No folder named \"data\" was found, creating one... (This message is harmless)" ) os.makedirs("data") if not os.path.isdir("assets"): log.critical( "There is no folder named \"assets\"! Please go to the github repo and download the assets folder!" ) os._exit(1)
def load_opus_lib(opus_libs=OPUS_LIBS): if opus.is_loaded(): return True for opus_lib in opus_libs: try: opus.load_opus(opus_lib) log.debug("Loaded opus lib \"{}\"".format(opus_lib)) return except OSError: pass log.critical("Could not load an opus lib. Tried {}".format(", ".join(opus_libs))) os._exit(1)
async def anime(self, ctx, *, name: str): """Searches MyAnimeList for the specified anime""" await self.bot.send_typing(ctx.message.channel) r = requests.get( "https://myanimelist.net/api/anime/search.xml?q={}".format(name), auth=requests.auth.HTTPBasicAuth(config._malUsername, config._malPassword)) if r.status_code == 401: log.critical( "The MyAnimeList credinals are incorrect, please check your MyAnimeList login information in the config." ) await self.bot.say( "The MyAnimeList credinals are incorrect, contact the bot developer!" ) return with open("data/anime.xml", "wb") as xml: xml.write(r.content) try: xmldoc = minidom.parse("data/anime.xml") except XmlParserErrors.ExpatError: await self.bot.say( "Couldn't find any anime named `{}`".format(name)) return # pls no flame anime = xmldoc.getElementsByTagName("entry")[0] id = anime.getElementsByTagName("id")[0].firstChild.nodeValue title = anime.getElementsByTagName("title")[0].firstChild.nodeValue try: english = anime.getElementsByTagName( "english")[0].firstChild.nodeValue except: english = title episodes = anime.getElementsByTagName( "episodes")[0].firstChild.nodeValue score = anime.getElementsByTagName("score")[0].firstChild.nodeValue type = anime.getElementsByTagName("type")[0].firstChild.nodeValue status = anime.getElementsByTagName("status")[0].firstChild.nodeValue start_date = anime.getElementsByTagName( "start_date")[0].firstChild.nodeValue end_date = anime.getElementsByTagName( "end_date")[0].firstChild.nodeValue synopsis = saxutils.unescape( anime.getElementsByTagName("synopsis")[0].firstChild.nodeValue) synopsis = remove_html(synopsis) print(len(synopsis)) if len(synopsis) > 500: synopsis = synopsis[:500] + "..." url = "https://myanimelist.net/anime/{}".format(id) msg = "```Title: {}\nEnglish title: {}\nEpisodes: {}\nScore: {}\nType: {}\nStatus: {}\nStart date: {}\nEnd Date: {}```{}\nRead more: {}".format( title, english, episodes, score, type, status, start_date, end_date, synopsis, url) await self.bot.say(msg)
def run_checks(): if not os.path.isdir("data"): log.warning("No folder named \"data\" was found, creating one... (This message is harmless)") os.makedirs("data") if not os.path.isfile("data/languages.json"): log.warning("The file \"languages.json\" in the \"data\" folder was not found, creating one... (This message is harmless)") with open("data/languages.json", "w+") as file: file.write("{}") if not os.path.isdir("assets"): log.critical("There is no folder named \"assets\"! Please go to the github repo and download the assets folder!") os._exit(1)
def load_opus_lib(opus_libs=OPUS_LIBS): if opus.is_loaded(): return True for opus_lib in opus_libs: try: opus.load_opus(opus_lib) log.debug("Loaded opus lib \"{}\"".format(opus_lib)) return except OSError: pass log.critical("Could not load an opus lib. Tried {}".format( ", ".join(opus_libs))) os._exit(1)
def __init__(self): if not os.path.isfile("config/config.ini"): if not os.path.isfile("config/config.ini.example"): log.critical("There is no \"config.ini.example\" file in the \"config\" folder! Please go to the github repo and download it and then put it in the \"config\" folder!") os._exit(1) else: shutil.copy("config/config.ini.example", "config/config.ini") log.warning("Created the \"config.ini\" file in the config folder! Please edit the config and then run the bot again!") os._exit(1) self.config_file = "config/config.ini" config = configparser.ConfigParser(interpolation=None) config.read(self.config_file, encoding="utf-8") sections = {"Credentials", "Bot", "Status", "Logging", "MyAnimeList", "Osu", "Steam"}.difference(config.sections()) if sections: log.critical("Could not load a section in the config file, please obtain a new config file from the github repo if regenerating the config doesn't work!") os._exit(1) self._token = config.get("Credentials", "Token", fallback=Defaults.token) self._dbots_token = config.get("Credentials", "Dbots_Token", fallback=Defaults.dbots_token) self._carbonitex_key = config.get("Credentials", "Carbonitex_Key", fallback=Defaults.carbonitex_key) self.owner_id = config.getint("Bot", "Owner_ID", fallback=Defaults.owner_id) self.command_prefix = config.get("Bot", "Command_Prefix", fallback=Defaults.command_prefix) self.max_nsfw_count = config.getint("Bot", "Max_NSFW_Count", fallback=Defaults.max_nsfw_count) self.dev_ids = config.get("Bot", "Developer_IDs", fallback=Defaults.dev_ids) self.support_ids = config.get("Bot", "Support_IDs", fallback=Defaults.support_ids) self.skip_votes_needed = config.getint("Bot", "Skip_Votes_Needed", fallback=Defaults.skip_votes_needed) self.lock_status = config.getboolean("Status", "Lock_Status", fallback=Defaults.lock_status) self.enable_default_status = config.getboolean("Status", "Enable_Default_Status", fallback=Defaults.enable_default_status) self.default_status_name = config.get("Status", "Default_Status_Name", fallback=Defaults.default_status_name) self.default_status_type = config.get("Status", "Default_Status_Type", fallback=Defaults.default_status_type) self.debug = config.getboolean("Logging", "Debug", fallback=Defaults.debug) self.channel_logger_id = config.get("Logging", "Channel_Logger_ID", fallback=Defaults.channel_logger_id) self.log_time_format = config.get("Logging", "Time_Format", fallback=Defaults.log_time_format) self.log_date_format = config.get("Logging", "Date_Format", fallback=Defaults.log_date_format) self.enableMal = config.getboolean("MyAnimeList", "enable", fallback=Defaults.enableMal) self._malUsername = config.get("MyAnimeList", "username", fallback=Defaults.malUsername) self._malPassword = config.get("MyAnimeList", "password", fallback=Defaults.malPassword) self.enableOsu = config.getboolean("Osu", "enable", fallback=Defaults.enableOsu) self._osuKey = config.get("Osu", "key", fallback=Defaults.osuKey) self.enableSteam = config.get("Steam", "enable", fallback=Defaults.osuKey) self._steamAPIKey = config.get("Steam", "key", fallback=Defaults.osuKey) self._twitchClientID = config.get("Twitch", "client_id", fallback=Defaults.twitchClientID) self._googleAPIKey = config.get("Google", "api_key", fallback=Defaults.googleAPIKey) self._catAPIKey = config.get("Cats", "api_key", fallback=Defaults.googleAPIKey) self.check()
def __init__(self): if not os.path.isfile("config/config.ini"): if not os.path.isfile("config/config.ini.example"): log.critical("There is no \"config.ini.example\" file in the \"config\" folder! Please go to the github repo and download it and then put it in the \"config\" folder!") os._exit(1) else: shutil.copy("config/config.ini.example", "config/config.ini") log.warning("Created the \"config.ini\" file in the config folder! Please edit the config and then run the bot again!") os._exit(1) self.config_file = "config/config.ini" config = configparser.ConfigParser(interpolation=None) config.read(self.config_file, encoding="utf-8") sections = {"Credentials", "Bot", "Status", "Logging", "MyAnimeList", "Osu", "Steam"}.difference(config.sections()) if sections: log.critical("Could not load a section in the config file, please obtain a new config file from the github repo if regenerating the config doesn't work!") os._exit(1) self._token = config.get("Credentials", "Token", fallback=Defaults.token) self._dbots_token = config.get("Credentials", "Dbots_Token", fallback=Defaults.dbots_token) self._carbonitex_key = config.get("Credentials", "Carbonitex_Key", fallback=Defaults.carbonitex_key) self.owner_id = config.getint("Bot", "Owner_ID", fallback=Defaults.owner_id) self.command_prefix = config.get("Bot", "Command_Prefix", fallback=Defaults.command_prefix) self.max_nsfw_count = config.getint("Bot", "Max_NSFW_Count", fallback=Defaults.max_nsfw_count) self.dev_ids = config.get("Bot", "Developer_IDs", fallback=Defaults.dev_ids) self.support_ids = config.get("Bot", "Support_IDs", fallback=Defaults.support_ids) self.skip_votes_needed = config.getint("Bot", "Skip_Votes_Needed", fallback=Defaults.skip_votes_needed) self.lock_status = config.getboolean("Status", "Lock_Status", fallback=Defaults.lock_status) self.enable_default_status = config.getboolean("Status", "Enable_Default_Status", fallback=Defaults.enable_default_status) self.default_status_name = config.get("Status", "Default_Status_Name", fallback=Defaults.default_status_name) self.default_status_type = config.get("Status", "Default_Status_Type", fallback=Defaults.default_status_type) self.debug = config.getboolean("Logging", "Debug", fallback=Defaults.debug) self.channel_logger_id = config.get("Logging", "Channel_Logger_ID", fallback=Defaults.channel_logger_id) self.log_time_format = config.get("Logging", "Time_Format", fallback=Defaults.log_time_format) self.log_date_format = config.get("Logging", "Date_Format", fallback=Defaults.log_date_format) self.enableMal = config.getboolean("MyAnimeList", "enable", fallback=Defaults.enableMal) self._malUsername = config.get("MyAnimeList", "username", fallback=Defaults.malUsername) self._malPassword = config.get("MyAnimeList", "password", fallback=Defaults.malPassword) self.enableOsu = config.getboolean("Osu", "enable", fallback=Defaults.enableOsu) self._osuKey = config.get("Osu", "key", fallback=Defaults.osuKey) self.enableSteam = config.get("Steam", "enable", fallback=Defaults.osuKey) self._steamAPIKey = config.get("Steam", "key", fallback=Defaults.osuKey) self._twitchClientID = config.get("Twitch", "client_id", fallback=Defaults.twitchClientID) self._googleAPIKey = config.get("Google", "api_key", fallback=Defaults.googleAPIKey) self.check()
def run_checks(): if not os.path.isdir("data"): log.warning( "No folder named \"data\" was found, creating one... (This message is harmless)" ) os.makedirs("data") if not os.path.isfile("data/languages.json"): log.warning( "The file \"languages.json\" in the \"data\" folder was not found, creating one... (This message is harmless)" ) with open("data/languages.json", "w+") as file: file.write("{}") if not os.path.isdir("assets"): log.critical("You need an assets folder") os._exit(1)
async def manga(self, ctx, *, name:str): """Searches MyAnimeList for the specified manga""" await ctx.channel.trigger_typing() r = requests.get("https://myanimelist.net/api/manga/search.xml?q={}".format(name), auth=requests.auth.HTTPBasicAuth(config._malUsername, config._malPassword)) if r.status_code == 401: log.critical("The MyAnimeList credinals are incorrect, please check your MyAnimeList login information in the config.") await ctx.send(Language.get("myanimelist.incorrect_creds", ctx)) return try: xmldoc = minidom.parseString(r.text) except XmlParserErrors.ExpatError: await ctx.send(Language.get("myanimelist.no_manga_found", ctx).format(name)) return # pls no flame manga = xmldoc.getElementsByTagName("entry")[0] id = manga.getElementsByTagName("id")[0].firstChild.nodeValue title = manga.getElementsByTagName("title")[0].firstChild.nodeValue try: english = manga.getElementsByTagName("english")[0].firstChild.nodeValue except: english = title chapters = manga.getElementsByTagName("chapters")[0].firstChild.nodeValue volumes = manga.getElementsByTagName("volumes")[0].firstChild.nodeValue score = manga.getElementsByTagName("score")[0].firstChild.nodeValue type = manga.getElementsByTagName("type")[0].firstChild.nodeValue status = manga.getElementsByTagName("status")[0].firstChild.nodeValue start_date = manga.getElementsByTagName("start_date")[0].firstChild.nodeValue end_date = manga.getElementsByTagName("end_date")[0].firstChild.nodeValue image = manga.getElementsByTagName("image")[0].firstChild.nodeValue synopsis = saxutils.unescape(manga.getElementsByTagName("synopsis")[0].firstChild.nodeValue) synopsis = remove_html(synopsis) if len(synopsis) > 300: synopsis = synopsis[:300] + "..." url = "https://myanimelist.net/manga/{}".format(id) fields = {Language.get("myanimelist.english_title", ctx):english, Language.get("myanimelist.chapaters", ctx):chapters, Language.get("myanimelist.volumes", ctx):volumes, Language.get("myanimelist.mal_history", ctx):score, Language.get("myanimelist.type", ctx):type, Language.get("myanimelist.status", ctx):status, Language.get("myanimelist.start_date", ctx):start_date, Language.get("myanimelist.end_date", ctx):end_date} embed = make_list_embed(fields) embed.title = title embed.description = synopsis embed.url = url embed.color = 0xFF0000 embed.set_thumbnail(url=image) await ctx.send(embed=embed)
async def set_default_status(): if not config.enable_default_status: return type = config.default_status_type name = config.default_status_name try: type = discord.Status(type) except: type = discord.Status.online if name is not None: if config.default_status_type == "stream": if config.default_status_name is None: log.critical("If the status type is set to \"stream\" then the default status game must be specified") os._exit(1) status = discord.Activity(name=name, url="http://twitch.tv/ZeroEpoch1969", type=discord.ActivityType.streaming) else: status = discord.Activity(name=name, type=discord.ActivityType.playing) await bot.change_presence(status=type, activity=status) else: await bot.change_presence(status=type)
async def set_default_status(): if not config.enable_default_status: return type = config.default_status_type game = config.default_status_name try: type = discord.Status(type) except: type = discord.Status.online if game is not None: if config.default_status_type == "stream": if config.default_status_name is None: log.critical("If the status type is set to \"stream\" then the default status game must be specified") os._exit(1) game = discord.Game(name=game, url="http://twitch.tv/CreeperSeth", type=1) else: game = discord.Game(name=game) await bot.change_presence(status=type, game=game) else: await bot.change_presence(status=type)
async def osu(self, ctx, *, username: str): """Gets an osu! profile stats with the specified name""" if not config.enableOsu: await self.bot.say("The osu! command has been disabled.") return try: import osuapi except ImportError: log.critical( "The osu api is enabled, but the osuapi module was not found! Please run \"pip install osuapi\"" ) await self.bot.say( "Couldn't import the osu! api module, contact the bot developer!" ) return await self.bot.send_typing(ctx.message.channel) api = osuapi.OsuApi(config._osuKey, connector=osuapi.AHConnector()) try: user = await api.get_user(username) except osuapi.HTTPError as e: if e.code == 401: log.critical( "An invalid osu! api key was set, please check the config for instructions on how to get a proper api key!" ) await self.bot.say( "An invalid osu! api key was set, contact the bot developer!" ) return else: log.critical( "An unknown error occured while trying to get an osu! profile." ) await self.bot.say( "An unknown error occured while trying to get that user's osu! profile, contact the bot developer!" ) return try: user = user[0] except IndexError: await self.bot.say( "Could find any osu! profile named `{}`".format(username)) return fields = { "ID": user.user_id, "Country": user.country, "Level": int(user.level), "Hits": user.total_hits, "Score": user.total_score, "Accuracy": "{0:.2f}%".format(user.accuracy), "Play Count": user.playcount, "Ranked Score": user.ranked_score, "A rank": user.count_rank_a, "S rank": user.count_rank_s, "SS rank": user.count_rank_ss } embed = make_list_embed(fields) embed.title = "{}'s Osu! Stats".format(user.username) embed.color = 0xFF00FF embed.set_thumbnail(url="http://s.ppy.sh/a/{}".format(user.user_id)) await self.bot.say(embed=embed)
async def osu(self, ctx, *, username:str): """Gets an osu! profile stats with the specified name""" if not config.enableOsu: await ctx.send(Language.get("information.osu_command_disabled", ctx)) return try: import osuapi except ImportError: log.critical("The osu api is enabled, but the osuapi module was not found! Please run \"pip install osuapi\"") await ctx.send(Language.get("osu_import_fail", ctx)) return await ctx.channel.trigger_typing() api = osuapi.OsuApi(config._osuKey, connector=osuapi.AHConnector()) try: user = await api.get_user(username) except osuapi.HTTPError as e: if e.code == 401: log.critical("An invalid osu! api key was set, please check the config for instructions on how to get a proper api key!") await ctx.send(Language.get("information.osu_invalid_key", ctx)) return else: log.critical("An unknown error occured while trying to get an osu! profile.") await ctx.send(Language.get("information.osu_unknown_error", ctx)) return try: user = user[0] except IndexError: await ctx.send(Language.get("information.no_osu_profile_found", ctx).format(username)) return fields = {Language.get("information.id", ctx):user.user_id, Language.get("information.country", ctx):user.country, Language.get("information.level", ctx):int(user.level), Language.get("information.hits", ctx):user.total_hits, Language.get("information.score", ctx):user.total_score, Language.get("information.accuracy", ctx):"{0:.2f}%".format(user.accuracy), Language.get("information.play_count", ctx):user.playcount, Language.get("information.ranked_score", ctx):user.ranked_score, Language.get("information.a_rank", ctx):user.count_rank_a, Language.get("information.s_rank", ctx):user.count_rank_s, Language.get("information.ss_rank", ctx):user.count_rank_ss} embed = make_list_embed(fields) embed.title = Language.get("information.osu_stats_title", ctx).format(user.username) embed.color = 0xFF00FF embed.set_thumbnail(url="http://s.ppy.sh/a/{}".format(user.user_id)) await ctx.send(embed=embed)
async def osu(self, ctx, *, username: str): """Gets an osu! profile stats with the specified name""" if not config.enableOsu: await self.bot.say("The osu command is currently disabled.") return try: import osuapi except ImportError: log.critical( "The osu api is enabled, but the osuapi module was not found! Please run \"pip install osuapi\"" ) await self.bot.say( "Couldn't import the osu! api module, contact the bot developer!" ) return await self.bot.send_typing(ctx.message.channel) api = osuapi.OsuApi(config._osuKey, connector=osuapi.AHConnector()) try: user = await api.get_user(username) except osuapi.HTTPError as e: if e.code == 401: log.critical( "An invalid osu! api key was set, please check the config for instructions on how to get a proper api key!" ) await self.bot.say( "An invalid osu! api key was set, contact the bot developer!" ) return else: log.critical( "An unknown error occured while trying to get an osu! profile." ) await self.bot.say( "An unknown error occured while trying to get that user's osu! profile, contact the bot developer!" ) return try: user = user[0] except IndexError: await self.bot.say( "Could find any osu! profile named `{}`".format(username)) return results = discord.Embed(description="\u200b") results.title = user.username + "'s osu! stats" results.add_field(name='ID', value=user.user_id) results.add_field(name='Country', value=user.country) results.add_field(name='Level', value=int(user.level)) results.add_field(name='Total Hits', value=user.total_hits) results.add_field(name='Total Score', value=user.total_score) results.add_field(name='Accuracy', value="{0:.2f}%".format(user.accuracy)) results.add_field(name='Play Count', value=user.playcount) results.add_field(name='Ranked Score', value=user.ranked_score) results.add_field(name='A Rank Count/S Rank Count/SS Rank Count', value="{}/{}/{}".format(user.ranked_score, user.count_rank_a, user.count_rank_s, user.count_rank_ss)) await self.bot.say(embed=results)
async def osu(self, ctx, *, username: str): """Gets an osu! profile stats with the specified name""" if not config.enableOsu: await self.bot.say("The osu! command has been disabled.") return try: import osuapi except ImportError: log.critical( "The osu api is enabled, but the osuapi module was not found! Please run \"pip install osuapi\"" ) await self.bot.say( "Couldn't import the osu! api module, contact the bot developer!" ) return await self.bot.send_typing(ctx.message.channel) api = osuapi.OsuApi(config._osuKey, connector=osuapi.AHConnector()) try: user = await api.get_user(username) except osuapi.HTTPError as e: if e.code == 401: log.critical( "An invalid osu! api key was set, please check the config for instructions on how to get a proper api key!" ) await self.bot.say( "An invalid osu! api key was set, contact the bot developer!" ) return else: log.critical( "An unknown error occured while trying to get an osu! profile." ) await self.bot.say( "An unknown error occured while trying to get that user's osu! profile, contact the bot developer!" ) return try: user = user[0] except IndexError: await self.bot.say( "Could find any osu! profile named `{}`".format(username)) return results = xl.format( "~~~~~~~~~~Osu! Stats~~~~~~~~~~\nUsername: {}\nID: {}\nCountry: {}\nLevel: {}\nTotal hits: {}\nTotal score: {}\nAccuracy: {}\nPlay count: {}\nRanked score: {}\nA rank: {}\nS rank: {}\nSS rank: {}\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" .format("\"" + user.username + "\"", user.user_id, "\"" + user.country + "\"", int(user.level), user.total_hits, user.total_score, "{0:.2f}%".format(user.accuracy), user.playcount, user.ranked_score, user.count_rank_a, user.count_rank_s, user.count_rank_ss)) await self.bot.say(results)
def check(self): if not self._token: log.critical( "No token was specified in the config, please put your bot's token in the config." ) os._exit(1) if not self.owner_id: log.critical( "No owner ID was specified in the config, please put your ID for the owner ID in the config" ) os._exit(1) if len(self.dev_ids) is not 0: try: ids = self.dev_ids.split() self.dev_ids = [] for id in ids: self.dev_ids.append(int(id)) except: log.warning( "Developer IDs are invalid, all developer IDs have been ignored!" ) self.dev_ids = Defaults.dev_ids if self.enableMal: if not self._malUsername and not self._malPassword: log.critical( "The MyAnimeList module was enabled, but no MAL credinals were specified!" ) if not self._malUsername: log.critical( "The MyAnimeList module was enabled, but no MAL username was specified!" ) os._exit(1) if not self._malPassword: log.critical( "The MyAnimeList module was enabled, but no MAL password was specified!" ) os._exit(1) if self.enableOsu: if not self._osuKey: log.critical( "The osu! module was enabled but no osu! api key was specified!" ) os._exit(1)
async def manga(self, ctx, *, name: str): """Searches MyAnimeList for the specified manga""" await self.bot.send_typing(ctx.message.channel) r = requests.get( "https://myanimelist.net/api/manga/search.xml?q={}".format(name), auth=requests.auth.HTTPBasicAuth(config._malUsername, config._malPassword)) if r.status_code == 401: log.critical( "The MyAnimeList credinals are incorrect, please check your MyAnimeList login information in the config." ) await self.bot.say( "The MyAnimeList credinals are incorrect, contact the bot developer!" ) return try: xmldoc = minidom.parseString(r.text) except XmlParserErrors.ExpatError: await self.bot.say( "Couldn't find any manga named `{}`".format(name)) return # pls no flame manga = xmldoc.getElementsByTagName("entry")[0] id = manga.getElementsByTagName("id")[0].firstChild.nodeValue title = manga.getElementsByTagName("title")[0].firstChild.nodeValue try: english = manga.getElementsByTagName( "english")[0].firstChild.nodeValue except: english = title chapters = manga.getElementsByTagName( "chapters")[0].firstChild.nodeValue volumes = manga.getElementsByTagName("volumes")[0].firstChild.nodeValue score = manga.getElementsByTagName("score")[0].firstChild.nodeValue type = manga.getElementsByTagName("type")[0].firstChild.nodeValue status = manga.getElementsByTagName("status")[0].firstChild.nodeValue start_date = manga.getElementsByTagName( "start_date")[0].firstChild.nodeValue end_date = manga.getElementsByTagName( "end_date")[0].firstChild.nodeValue image = manga.getElementsByTagName("image")[0].firstChild.nodeValue synopsis = saxutils.unescape( manga.getElementsByTagName("synopsis")[0].firstChild.nodeValue) synopsis = remove_html(synopsis) if len(synopsis) > 300: synopsis = synopsis[:300] + "..." url = "https://myanimelist.net/manga/{}".format(id) fields = { "English Title": english, "Chapters": chapters, "Volumes": volumes, "MAL Score": score, "Type": type, "Status": status, "Start Date": start_date, "End Date": end_date } embed = make_list_embed(fields) embed.title = title embed.description = synopsis embed.url = url embed.color = 0xFF0000 embed.set_thumbnail(url=image) await self.bot.say(embed=embed)
def __init__( self, herokudeploy=False): # change if you're running on a pc or vps if herokudeploy is True: if not os.path.isfile("/app/config/config.ini"): if not os.path.isfile("/app/config/config.ini.example"): log.critical( "There is no \"config.ini.example\" file in the \"config\" folder! Please go to the github repo and download it and then put it in the \"config\" folder!" ) os._exit(1) else: shutil.copy("/app/config/config.ini.example", "/app/config/config.ini") log.warning( "Created the \"config.ini\" file in the config folder! Please edit the config and then run the bot again!" ) pass else: if not os.path.isfile("config/config.ini"): if not os.path.isfile("/app/config/config.ini.example"): log.critical( "There is no \"config.ini.example\" file in the \"config\" folder! Please go to the github repo and download it and then put it in the \"config\" folder!" ) os._exit(1) else: shutil.copy("config/config.ini.example", "config/config.ini") log.warning( "Created the \"config.ini\" file in the config folder! Please edit the config and then run the bot again!" ) os._exit(1) self.config_file = "config/config.ini" config = configparser.ConfigParser(interpolation=None) config.read(self.config_file, encoding="utf-8") if herokudeploy is True: sections = { "Credentials", "Bot", "Status", "Logging", "Osu", "Guild Wars 2", "Google", "Last.fm", "Hypixel" }.difference(config.sections()) if sections: log.critical( "Could not load a section in the config file, please obtain a new config file from the github repo if regenerating the config doesn't work!" ) os._exit(1) self._token = str(os.environ.get('BOT_TOKEN')) self._dbots_token = str(os.environ.get('DBOTS_TOKEN')) self._steam_key = str(os.environ.get('STEAM_KEY')) self._darksky_key = str(os.environ.get('DARKSKY_KEY')) self.owner_id = config.get("Bot", "Owner_ID", fallback=Defaults.owner_id) self.command_prefix = config.get("Bot", "Command_Prefix", fallback=Defaults.command_prefix) self.max_nsfw_count = config.getint( "Bot", "Max_NSFW_Count", fallback=Defaults.max_nsfw_count) self.skip_votes_needed = config.getint( "Bot", "Skip_Votes_Needed", fallback=Defaults.skip_votes_needed) self.dev_ids = config.get("Bot", "Developer_IDs", fallback=Defaults.dev_ids) self.lock_status = config.getboolean("Status", "Lock_Status", fallback=Defaults.lock_status) self.enable_default_status = config.getboolean( "Status", "Enable_Default_Status", fallback=Defaults.enable_default_status) self.default_status_name = config.get( "Status", "Default_Status_Name", fallback=Defaults.default_status_name) self.default_status_type = config.get( "Status", "Default_Status_Type", fallback=Defaults.default_status_type) self.debug = config.getboolean("Logging", "Debug", fallback=Defaults.debug) self.channel_logger_id = config.get( "Logging", "Channel_Logger_ID", fallback=Defaults.channel_logger_id) self.log_timeformat = config.get("Logging", "Time_Format", fallback=Defaults.log_timeformat) self.enableOsu = config.getboolean("Osu", "enable", fallback=Defaults.enableOsu) self._osuKey = str(os.environ.get('OSU_KEY')) self._gw2Key = str(os.environ.get('GW2_KEY')) self._googleKey = str(os.environ.get('GOOGLE_KEY')) self._lastfmapiKey = str(os.environ.get('LASTFM_API')) self._lastfmSecret = str(os.environ.get('LASTFM_SECRET')) self._hypixelKey = str(os.environ.get('HYPIXEL_KEY')) else: sections = { "Credentials", "Bot", "Status", "Logging", "Osu", "Guild Wars 2", "Google", "Last.fm", "Hypixel" }.difference(config.sections()) if sections: log.critical( "Could not load a section in the config file, please obtain a new config file from the github repo if regenerating the config doesn't work!" ) os._exit(1) self._token = config.get("Credentials", "Token", fallback=Defaults.token) self._dbots_token = config.get("Credentials", "Dbots_Token", fallback=Defaults.dbots_token) self._steam_key = config.get("Credentials", "Steam_Key", fallback=Defaults.steam_key) self._darksky_key = config.get("Credentials", "DarkSky_Key", fallback=Defaults.steam_key) self.owner_id = config.get("Bot", "Owner_ID", fallback=Defaults.owner_id) self.command_prefix = config.get("Bot", "Command_Prefix", fallback=Defaults.command_prefix) self.max_nsfw_count = config.getint( "Bot", "Max_NSFW_Count", fallback=Defaults.max_nsfw_count) self.skip_votes_needed = config.getint( "Bot", "Skip_Votes_Needed", fallback=Defaults.skip_votes_needed) self.dev_ids = config.get("Bot", "Developer_IDs", fallback=Defaults.dev_ids) self.lock_status = config.getboolean("Status", "Lock_Status", fallback=Defaults.lock_status) self.enable_default_status = config.getboolean( "Status", "Enable_Default_Status", fallback=Defaults.enable_default_status) self.default_status_name = config.get( "Status", "Default_Status_Name", fallback=Defaults.default_status_name) self.default_status_type = config.get( "Status", "Default_Status_Type", fallback=Defaults.default_status_type) self.debug = config.getboolean("Logging", "Debug", fallback=Defaults.debug) self.channel_logger_id = config.get( "Logging", "Channel_Logger_ID", fallback=Defaults.channel_logger_id) self.log_timeformat = config.get("Logging", "Time_Format", fallback=Defaults.log_timeformat) self.enableOsu = config.getboolean("Osu", "enable", fallback=Defaults.enableOsu) self._osuKey = config.get("Osu", "key", fallback=Defaults.osuKey) self._gw2Key = config.get("Guild Wars 2", "key", fallback=Defaults.gw2Key) self._googleKey = config.get("Google", "key", fallback=Defaults.googleKey) self._lastfmapiKey = config.get("Last.fm", "api", fallback=Defaults.lastfmapiKey) self._lastfmSecret = config.get("Last.fm", "secret", fallback=Defaults.lastfmSecret) self._hypixelKey = config.get("Hypixel", "key", fallback=Defaults.hypixelKey) self.check()
def check(self): if not self._token: log.critical( "No token was specified in the config, please put your bot's token in the config." ) os._exit(1) if not self.owner_id: log.critical( "No owner ID was specified in the config, please put your ID for the owner ID in the config" ) os._exit(1) if not self._dbots_token: log.warning( "No token for Discord Bots Stats was specified, this will not work until a token is specified in the config." ) if not self._steam_key: log.warning( "No key was specified for Steam, the steam extension will not work until it is specified" ) if not self._darksky_key: log.warning( "No key was specified Dark Sky, the weather extension will not work until it is specified" ) if not self.skip_votes_needed: log.info( "No amount of skip votes needed to skip a song has been set. Falling back to only one vote needed." ) if len(self.dev_ids) != 0: try: ids = self.dev_ids.split() self.dev_ids = [] for id in ids: self.dev_ids.append(int(id)) except: log.warning( "Developer IDs are invalid, all developer IDs have been ignored!" ) self.dev_ids = Defaults.dev_ids if self.enableOsu: if not self._osuKey: log.critical( "The osu! module was enabled but no osu! api key was specified!" ) os._exit(1) if not self._gw2Key: log.critical( "There's no Guild Wars 2 key! Going in without one...") if not self._googleKey: log.critical( "There's no LocationIQ key! Location services for weather and IP tracking services will not work!" ) if not self._darksky_key: log.critical( "The weather cog will not work without a Dark Sky key set!") if not self._lastfmapiKey: log.critical( "The last.fm cog will not work without the api key at least set." ) if not self._hypixelKey: log.warning("Hypixel cog will not work without a key, disabling")
def check(self): if not self._token: log.critical("No token was specified in the config, please put your bot's token in the config.") os._exit(1) if not self.owner_id: log.critical("No owner ID was specified in the config, please put your ID for the owner ID in the config") os._exit(1) if len(self.dev_ids) is not 0: try: ids = self.dev_ids.split() self.dev_ids = [] for id in ids: self.dev_ids.append(int(id)) except: log.warning("Developer IDs are invalid, all developer IDs have been ignored!") self.dev_ids = Defaults.dev_ids if len(self.support_ids) is not 0: try: ids = self.support_ids.split() self.support_ids = [] for id in ids: self.support_ids.append(int(id)) except: log.warning("Support IDs are invalid, all support member IDs have been ignored!") self.support_ids = Defaults.support_ids if self.enableMal: if not self._malUsername and not self._malPassword: log.critical("The MyAnimeList module was enabled, but no MAL credinals were specified!") if not self._malUsername: log.critical("The MyAnimeList module was enabled, but no MAL username was specified!") os._exit(1) if not self._malPassword: log.critical("The MyAnimeList module was enabled, but no MAL password was specified!") os._exit(1) if self.enableOsu and not self._osuKey: log.critical("The osu! module was enabled but no osu! api key was specified!") os._exit(1)