async def query(context, *args, **kwargs): if len(args) < 1: return await koduck.sendmessage( context["message"], sendcontent= "This command can sort battlechips, NCPs, and powers by Category, and single out Crossover Content chips! Please type `>help query` for more information." ) table = yadon.ReadTable("querydata") results = [] for chipname, values in table.items(): if args[0].lower() == values[0].lower(): results.append(chipname) elif values[1].startswith("[") and args[0].lower( ) == values[1][1:values[1].index("]")].lower(): results.append(chipname) if not results: return await koduck.sendmessage( context["message"], sendcontent= "I can't find any chips, NCPs, or Powers in that Category, or from that Crossover title." ) else: return await koduck.sendmessage( context["message"], sendcontent= "Please check `>help query` for what chip markings mean!\n**_Battlechips/NCPs/Powers in the_ ``'{}'`` _category, or from that specific Crossover..._**\n_{}_" .format(args[0], ", ".join(results)))
async def daemon(context, *args, **kwargs): if len(args) < 1: return await koduck.sendmessage( context["message"], sendcontent= "Lists the complete information of a Daemon for DarkChip rules.") table = yadon.ReadTable("daemondata") case_insensitive = {key.lower(): key for key in table.keys()} try: name = case_insensitive[args[0].lower()] except KeyError: return await koduck.sendmessage( context["message"], sendcontent="I don't recognize that Daemon!") values = table[name] Name = "_''{}''_".format(values[0]) Domain = "**__Domain:__** _{}_".format(values[1]) Tribute = "\n\n**__Tribute:__** _{}_".format(values[2]) ChaosUnison = "\n\n**__ChaosUnison:__** _{}_".format(values[3]) SignatureChip = "\n\n**__Signature DarkChip:__** _{}_".format(values[4]) Description = "{}{}{}{}".format(Domain, Tribute, ChaosUnison, SignatureChip) embed = discord.Embed(title="**__{}__**".format("{}".format(name)), color=0x000000) embed.set_thumbnail(url=values[5]) embed.add_field(name=Name, value=Description) return await koduck.sendmessage(context["message"], sendembed=embed)
async def virus(context, *args, **kwargs): if len(args) < 1: return await koduck.sendmessage( context["message"], sendcontent= "Give me the name of a virus and I can pull up its info for you!") elif len(args) > 5: return await koduck.sendmessage( context["message"], sendcontent="Too many viruses, no spamming!") table = yadon.ReadTable("virusdata") case_insensitive = {key.lower(): key for key in table.keys()} for arg in args: try: name = case_insensitive[args[0].lower()] except KeyError: return await koduck.sendmessage( context["message"], sendcontent="I don't recognize that virus!") continue values = table[name] embed = discord.Embed(title="__{}__".format(name), description="_{}_".format(table[name][17]), color=0x7c00ff) embed.set_thumbnail(url=values[19]) embed.set_footer(text="{}\n{}".format( "Category: {}".format(values[18]), "(Artwork by {})".format(values[20]) if values[20] != "-" else "")) await koduck.sendmessage(context["message"], sendembed=embed)
async def NCP(context, *args, **kwargs): if len(args) < 1: return await koduck.sendmessage( context["message"], sendcontent= "Give me the name of an NCP and I can pull up its info for you!") table = yadon.ReadTable("ncpdata") case_insensitive = {key.lower(): key for key in table.keys()} try: name = case_insensitive[args[0].lower()] except KeyError: return await koduck.sendmessage( context["message"], sendcontent="I don't recognize that NCP!") values = table[name] exabytes = values[0] power = values[1] description = values[2] crossover = values[3] #this determines embed colors if power in [ "LockOn", "Volley", "BlindMode", "Splash", "Tracker", "Refresh", "Reconfig", "Analyze", "Foresight", "Extend", "MapEdit", "HotSwap", "Disruption", "Firewall", "NoClip" ]: color = 0x81A7C6 elif power in [ "Breakcharge", "Followthrough", "Gutsy", "Shockwave", "Shatter", "Warp", "Afterimages", "JumpJets", "Sneakrun", "ArtfulDodger", "Regenerate", "Clear", "KineticArmor", "Reflect", "HyperArmor" ]: color = 0xDF8F8D elif power in [ "Overwrite", "ModelEdit", "Playback", "Harmless", "Hypnotize", "Rally", "Bodyguard", "Vengeance", "Glare", "Duel", "Save", "CodeInjection", "Shift", "Control", "Alt" ]: color = 0xF8E580 elif crossover in ["ChitChat"]: color = 0xff8000 elif crossover in ["Radical Spin"]: color = 0x3f5cff elif crossover in ["Skateboard Dog"]: color = 0xff0000 elif crossover in ["Mystic Lilies"]: color = 0x99004c elif crossover in ["Genso Network"]: color = 0xff605d else: color = 0xffffff embed = discord.Embed(title="__{}{}__".format( (name), " ({} Crossover NCP)".format(values[3]) if values[3] != "-" else ""), color=color) embed.add_field(name="**[{}{}]**".format( "{} EB".format(values[0]), "/{} Power Upgrade NCP".format(values[1]) if values[1] != "-" else ""), value="_{}_".format(values[2])) return await koduck.sendmessage(context["message"], sendembed=embed)
async def chip(context, *args, **kwargss): if len(args) < 1: return await koduck.sendmessage( context["message"], sendcontent= "Give me the name of a Battle Chip and I can pull up its info for you!" ) elif len(args) > 5: return await koduck.sendmessage( context["message"], sendcontent="Too many chips, no spamming!") table = yadon.ReadTable("chipdata") case_insensitive = {key.lower(): key for key in table.keys()} for arg in args: try: name = case_insensitive[arg.lower()] except KeyError: return await koduck.sendmessage( context["message"], sendcontent="I don't recognize that Battle Chip!") continue values = table[name] damage = values[0] type = values[1] description = values[2] categroy = values[3] tags = values[4] crossover = values[5] #this determines embed colors if "Mega" in values[5]: color = 0xA8E8E8 elif "ChitChat" in values[5]: color = 0xff8000 elif "Radical Spin" in values[5]: color = 0x3f5cff elif "Underground Broadcast" in values[5]: color = 0x73ab50 elif "Mystic Lilies" in values[5]: color = 0x99004c elif "Genso Network" in values[5]: color = 0xff605d elif "Leximancy" in values[5]: color = 0x481f65 elif "Dark" in values[5]: color = 0xB088D0 elif "Item" in values[3]: color = 0xffffff else: color = 0xbfbfbf embed = discord.Embed(title="__{}{}__".format( "{}".format(name), " ({} Chip)".format(values[5]) if values[5] != "-" else ""), color=color) embed.add_field(name="**[{}{}{}{}]**".format( "{} Damage/".format(values[0]) if values[0] != "-" else "", "{}/".format(values[1]) if values[1] != "-" else "", values[3], "/{}".format(values[4]) if values[4] != "-" else ""), value="_{}_".format(values[2])) await koduck.sendmessage(context["message"], sendembed=embed)
async def updatecommands(context, *args, **kwargs): tableitems = yadon.ReadTable(settings.commandstablename).items() if tableitems is not None: koduck.clearcommands() for name, details in tableitems: try: koduck.addcommand(name, globals()[details[0]], details[1], int(details[2])) except (KeyError, IndexError, ValueError): pass
def updatesettings(self): table = yadon.ReadTable(settings.settingstablename, named_columns=True) for key, setting in table.items(): try: value = setting["Value"] #try to convert into float or int, otherwise treat as string try: if float(value) % 1 == 0: value = int(value) else: value = float(value) except ValueError: value = value.replace("\\n", "\n").replace("\\t", "\t") except IndexError: value = None setattr(settings, key, value)
async def updatecommands(context, *args, **kwargs): tableitems = yadon.ReadTable(settings.commandstablename, named_columns=True).items() if tableitems is not None: koduck.clearcommands() for commandname, details in tableitems: if details["Module Name"] != "main": if details["Module Name"] not in sys.modules: try: importlib.import_module(details["Module Name"]) except ModuleNotFoundError: pass try: koduck.addcommand(commandname, getattr(sys.modules[details["Module Name"]], details["Method Name"]), details["Command Type"], int(details["Command Tier"])) except (KeyError, IndexError, ValueError): print("Failed to import command: {}".format(details)) else: try: koduck.addcommand(commandname, globals()[details["Method Name"]], details["Command Type"], int(details["Command Tier"])) except (KeyError, IndexError, ValueError): print("Failed to import command: {}".format(details))
async def element(context, *args, **kwargs): if len(args) < 1: return await koduck.sendmessage( context["message"], sendcontent= "Categories: **Nature, Fantasy, Science, Actions, Art, ???**") table = yadon.ReadTable("elementdata") if args[0].lower == "nature": element = random.randint(1, 36) #this is incomplete, don't mind this at all... else: element = random.randint(1, 216) values = table[str(element)] embed = discord.Embed(title="Picked a random {} Element...".format( values[1]), color=color) embed.add_field(name="**{}**".format(values[0])) return await koduck.sendmessage(context["message"], sendembed=embed)
async def tag(context, *args, **kwargs): if len(args) < 1: return await koduck.sendmessage( context["message"], sendcontent= "Give me a Battle Chip tag and I can pull up its info for you!") table = yadon.ReadTable("tagdata") case_insensitive = {key.lower(): key for key in table.keys()} try: name = case_insensitive[args[0].lower()] except KeyError: return await koduck.sendmessage( context["message"], sendcontent="I don't recognize that Battle Chip tag!") values = table[name] embed = discord.Embed(title="__{}{}__".format( "{}".format(name), " ({})".format(table[name][0]) if values[0] != "-" else ""), description=(table[name][1]), color=0x24ff00) return await koduck.sendmessage(context["message"], sendembed=embed)
async def bond(context, *args, **kwargs): if len(args) < 1: return await koduck.sendmessage( context["message"], sendcontent= "Give me a Bond Power and I can pull up its info for you!") table = yadon.ReadTable("bonddata") case_insensitive = {key.lower(): key for key in table.keys()} try: name = case_insensitive[args[0].lower()] except KeyError: return await koduck.sendmessage( context["message"], sendcontent="I don't recognize that Bond Power!") values = table[name] bondpoints = values[0] description = values[1] embed = discord.Embed(title="__{}__".format(name), color=0x24ff00) embed.add_field(name="**({})**".format(values[0]), value="_{}_".format(values[1])) return await koduck.sendmessage(context["message"], sendembed=embed)
async def power(context, *args, **kwargs): if len(args) < 1: return await koduck.sendmessage( context["message"], sendcontent= "Give me the name of a Navi Power and I can pull up its info for you!" ) table = yadon.ReadTable("powerdata") case_insensitive = {key.lower(): key for key in table.keys()} try: name = case_insensitive[args[0].lower()] except KeyError: return await koduck.sendmessage( context["message"], sendcontent="I don't recognize that NaviPower!") values = table[name] category = values[0] type = values[1] description = values[2] #this determines embed colors if category in ["Sense", "Info", "Coding"]: color = 0x81A7C6 elif category in ["Strength", "Speed", "Stamina"]: color = 0xDF8F8D elif category in ["Charm", "Bravery", "Affinity"]: color = 0xF8E580 else: color = 0xffffff embed = discord.Embed(title="__{}__".format(name), color=color) embed.add_field(name="**[{}{}]**".format( "{} Power".format(values[0]), "/{}".format(values[1]) if values[1] != "-" else ""), value="_{}_".format(values[2])) return await koduck.sendmessage(context["message"], sendembed=embed)
async def on_message(message): #ignore bot messages if message.author.bot: return #ignore messages not in whitelist if koduckinstance.getuserlevel( message.author.id) < settings.maxuserlevel and ( settings.restrictedmode == "true" and message.channel.id not in yadon.ReadTable( settings.channelwhitelisttablename).keys() ) and not message.channel.is_private: return try: #PARSE COMMAND AND PARAMS context, args, kwargs = KoduckContext(), [], {} context.koduck = koduckinstance context.message = message #PREFIX COMMANDS if message.content.startswith(settings.commandprefix): context.commandline = message.content[len(settings.commandprefix):] try: context.command = context.commandline[0:context.commandline. index(" ")].lower() context.paramline = context.commandline[context.commandline. index(" ") + 1:] except ValueError: context.command = context.commandline.lower() #Reset context if not a valid command if context.command not in koduckinstance.prefixcommands: koduckinstance.log(message, logresult=settings.message_unknowncommand) context, args, kwargs = KoduckContext(), [], {} context.message = message #Else parse params else: #Things within quotes should escape parsing #Find things within quotes, replace them with a number (which shouldn't have param delim) temp = context.paramline quotes = [] quotematches = list( re.finditer(r'(["])(?:\\.|[^\\])*?\1', temp)) quotematches.reverse() for quote in quotematches: start = quote.span()[0] end = quote.span()[1] temp = temp[0:start] + '"{}"'.format( len(quotes)) + temp[end:] quotes.append(quote.group()) parsedparams = temp.split(settings.paramdelim) #Weird thing if len(parsedparams) == 1 and parsedparams[0] == '': parsedparams = [] counter = len(quotes) - 1 #Put the quotes back in, without the quote marks themselves def putquotesback(text, quotes, counter): ans = text while text.find( '"{}"'.format(counter)) != -1 and counter >= 0: ans = ans.replace('"{}"'.format(counter), quotes[counter][1:-1], 1) counter -= 1 return (ans, counter) for param in parsedparams: #Find equal signs that aren't preceded by backslash equals = [ match.span()[0] for match in filter( lambda match: match.span()[0] == 0 or param[ match.span()[0] - 1] != "\\", re.finditer(r'=', param)) ] if len(equals) > 0: keyword, counter = putquotesback( param[:param.index("=")].strip(), quotes, counter) value, counter = putquotesback( param[param.index("=") + 1:].strip(), quotes, counter) kwargs[keyword] = value context.params.append("{}={}".format(keyword, value)) else: arg, counter = putquotesback(param.strip(), quotes, counter) args.append(arg) context.params.append(arg) #MATCH COMMANDS if not context.command: for commandname in koduckinstance.matchcommands: if commandname == message.content.lower(): context.command = commandname break #CONTAIN COMMANDS if not context.command: for commandname in koduckinstance.containcommands: if commandname in message.content.lower(): context.command = commandname break if not context.command: return #CHECK PERMISSIONS OF USER userlevel = koduckinstance.getuserlevel(message.author.id) if userlevel < koduckinstance.commands[context.command][2]: koduckinstance.log(message, settings.message_restrictedaccess) #notify user of restricted access only if it's a prefix command if context.command in koduckinstance.prefixcommands: await koduckinstance.sendmessage( message, sendcontent=settings.message_restrictedaccess) return koduckinstance.log(message) #RUN THE COMMAND function = koduckinstance.commands[context.command][0] result = await function(context, *args, **kwargs) if isinstance(result, str): koduckinstance.log(None, result) except Exception as e: exc_type, exc_value, _ = sys.exc_info() errormessage = "{}: {}".format(exc_type.__name__, exc_value) traceback.print_exc() await koduckinstance.sendmessage( message, sendcontent=settings.message_somethingbroke + "\n``{}``".format(errormessage)) koduckinstance.log( message, logresult=settings.message_unhandlederror.format(errormessage))
async def mysteryreward(context, *args, **kwargs): if len(args) < 1: return await koduck.sendmessage( context["message"], sendcontent= "Please specify either Common, Uncommon, or Rare MysteryData.") table = yadon.ReadTable("mysterydata") if args[0].lower() == "common": firstroll = random.randint(1, 3) if firstroll in [1, 2]: secondroll = random.randint(1, 36) elif firstroll == 3: secondroll = random.randint(37, 72) elif args[0].lower() == "uncommon": firstroll = random.randint(1, 3) if firstroll in [1, 2]: secondroll = random.randint(79, 114) elif firstroll == 3: secondroll = random.randint(115, 150) elif args[0].lower() == "rare": firstroll = random.randint(1, 3) if firstroll in [1, 2]: secondroll = random.randint(157, 192) elif firstroll == 3: secondroll = random.randint(193, 228) else: return await koduck.sendmessage( context["message"], sendcontent= "Please specify either Common, Uncommon, or Rare MysteryData.") values = table[str(secondroll)] #Color changes based on MysteryData Selection if (values[1]) in ["Common"]: color = 0x48C800 elif (values[1]) in ["Uncommon"]: color = 0x00E1DF elif (values[1]) in ["Rare"]: color = 0xD8E100 else: color = 0xffffff embed = discord.Embed( title="__{} MysteryData__".format(values[1]), description="_{} accessed the MysteryData..._\n \nGot: **{}{}! **". format(context["message"].author.mention, values[0], " " + values[2] if values[2] != "-" else ""), color=color) if values[1] in ["Common"]: embed.set_thumbnail( url= "https://raw.githubusercontent.com/gskbladez/meddyexe/master/virusart/commonmysterydata.png" ) elif values[1] in ["Uncommon"]: embed.set_thumbnail( url= "https://raw.githubusercontent.com/gskbladez/meddyexe/master/virusart/uncommonmysterydata.png" ) elif values[1] in ["Rare"]: embed.set_thumbnail( url= "https://raw.githubusercontent.com/gskbladez/meddyexe/master/virusart/raremysterydata.png" ) return await koduck.sendmessage(context["message"], sendembed=embed)
async def virusx(context, *args, **kwargs): if len(args) < 1: return await koduck.sendmessage( context["message"], sendcontent= "Give me the name of a virus and I can pull up its full info for you!" ) table = yadon.ReadTable("virusdata") case_insensitive = {key.lower(): key for key in table.keys()} try: name = case_insensitive[args[0].lower()] except KeyError: return await koduck.sendmessage( context["message"], sendcontent="I don't recognize that virus!") values = table[name] HP = values[0] Element = values[1] Mind = values[2] Body = values[3] Soul = values[4] Sense = values[5] Info = values[6] Coding = values[7] Strength = values[8] Speed = values[9] Stamina = values[10] Charm = values[11] Bravery = values[12] Affinity = values[13] Powers = values[14] Drops = values[15] Tags = values[16] Description = values[17] Category = values[18] Link = values[19] Artist = values[20] embed = discord.Embed(title="__{}__".format(name), color=0x7c00ff) stats = [ "HP", "Element", "Mind", "Body", "Soul", "Sense", "Info", "Coding", "Strength", "Speed", "Stamina", "Charm", "Bravery", "Affinity" ] stats_string = "" for i in range(5, len(stats)): if values[i] != "-": stats_string += "{} {}/".format(values[i], stats[i]) stats_string = stats_string[:-1] embed.set_thumbnail(url=values[19]) embed.add_field( name="**{} HP**".format(HP), value= "**_Element: {}_**\n{} Mind/{} Body/{} Soul\n{}\nPowers: {}\nDrops: {}\n**__Tags: {}__**\n_''{}''_" .format(Element, Mind, Body, Soul, stats_string, Powers, Drops, Tags, Description), inline=True) embed.set_footer(text="{}\n{}".format( "Category: {}".format(Category), "(Artwork by {})".format(Artist) if Artist != "-" else "")) return await koduck.sendmessage(context["message"], sendembed=embed)