async def ProposePriviousWaifu(Context, CmdName): WaifuFound = False async for message in Context.channel.history(limit=10): LastSentWaifu = HonestController.GetLastSeenWaifu(Context.author) if len(message.attachments) == 1 and not LastSentWaifu == None: WaifuFound = True for sin_attach in message.attachments: ProposeReply = "" if random.randint(0, 100) < 101: ProposeReply = BotUtilsLib.GetBotDialogByKey( "DLG_PROPOSE_YES", MentionMember=Context.author, MentionWaifu=LastSentWaifu) HonestController.SetUserWaifu(Context.author, LastSentWaifu) else: ProposeReply = BotUtilsLib.GetBotDialogByKey( "DLG_PROPOSE_NO", MentionMember=Context.author, MentionWaifu=LastSentWaifu) await Context.send(ProposeReply, file=discord.File( LastSentWaifu["FilePath"])) break if not WaifuFound: await Context.send(BotUtilsLib.GetBotDialogByKey("DLG_PROPOSE_NOFOUND") )
async def HandleCommandErrors(Bot, ContextObject, ErrorObject=None): ErrorChannel = Bot.get_channel( ConfigLib.GetChannelIDByAlias("CHNL_BOT_ERROR")) if isinstance(ErrorObject, commands.MissingRequiredArgument): await ContextObject.channel.send( BotUtilsLib.GetBotDialogByKey("DLG_ERR_MISS_ARG", MentionMember=ContextObject.author)) elif isinstance(ErrorObject, commands.CommandNotFound): await ContextObject.channel.send( BotUtilsLib.GetBotDialogByKey("DLG_ERR_CMD_NOTFOUND", MentionMember=ContextObject.author)) else: LOG.critical("Command has failed") LOG.error(ErrorObject) LOG.error('Exception in command {}:'.format(ContextObject.command)) traceback.print_exception(type(ErrorObject), ErrorObject, ErrorObject.__traceback__, file=sys.stderr) tb_str = "".join( traceback.format_exception(type(ErrorObject), ErrorObject, ErrorObject.__traceback__)) LOG.error(tb_str) await ErrorChannel.send(ErrorObject) await ContextObject.channel.send( BotUtilsLib.GetBotDialogByKey("DLG_ERR_UNKNOWN"))
def GiveUserRandomXP(MessageObject,RXP): CurrentXP=DynamoLib.GetMemberAttribute("XP",MessageObject.author) if CurrentXP!=None: RXP=RXP+CurrentXP time_int=BotUtilsLib.to_integer(datetime.now()) DynamoLib.SetMemberAttribute("XP",MessageObject.author,RXP) DynamoLib.SetMemberAttribute("LastUpdatedXPTime",MessageObject.author,time_int)
async def HelpCommand(Context, CmdName, CmndNameHelp=None): IsHelpModePrivate = HonestController.GetHelpMode(Context.channel, Context.author) CommandsInfo = ConfigLib.GetCommandInfo() """ ispub priv mode 0 0 0 0 1 1 1 0 1 1 1 1 """ cmndlist = [] for single_cmnd in CommandsInfo: if single_cmnd["IsPublic"] or IsHelpModePrivate: cmndlist.append(single_cmnd) if CmndNameHelp: commandfound = False for single_cmnd in cmndlist: if CmndNameHelp == single_cmnd["Name"]: commandfound = True await Context.send(single_cmnd["Description"]) if not commandfound: await Context.send( "Sorry I didn't find any command named " + CmndNameHelp + "\n> use **ht help** to get list of our commands") else: allcommands = "> " for sin_cmnd in cmndlist: allcommands = allcommands + "`" + sin_cmnd["Name"] + "` " await Context.send( BotUtilsLib.GetBotDialogByKey("DLG_HELP") + allcommands)
async def RemoveUser(Context, CmdName, member_mention): user_id = BotUtilsLib.GetMemberIDFromMention(member_mention) MemberObject = Context.guild.get_member(int(user_id)) if (MemberObject): await Context.guild.kick(MemberObject) else: await Context.guild.kick("No member found")
async def SendMyWaifu(Context, CmdName): UserWaifu = HonestController.GetUserWaifu(Context.author) if UserWaifu == {} or UserWaifu == None: await Context.send( BotUtilsLib.GetBotDialogByKey("DLG_PROPOSE_NOMARRIED")) return UserWaifuData = "> Name:" + UserWaifu["Name"] await Context.send(UserWaifuData, file=discord.File(UserWaifu["FilePath"]))
async def ManageLevel(bot, MessageObject): CurrentLevel = GetUserCurrentLevel(MessageObject.author) GiveUserXP(MessageObject) NewLevel = GetUserCurrentLevel(MessageObject.author) if CurrentLevel < NewLevel: await MessageObject.channel.send( BotUtilsLib.GetBotDialogByKey("DLG_LEVEL_UP", MentionMember=MessageObject.author, MentionLevel=NewLevel)) await RoleEngine.UpdateMemberRole(MessageObject.author, NewLevel)
async def SendMemberIntro(Context, CmdName, member_mention=None): if not "@" in member_mention: await Context.send("Please Mention member using @<member_name>") else: user_id = BotUtilsLib.GetMemberIDFromMention(member_mention) if user_id == 0: await Context.send("Member Not found!") else: UserIntro = HonestController.GetAllUserData( Context.guild.get_member(int(user_id))) await Context.send(UserIntro["Introduction"])
async def ValidateCommand(*args, **kwargs): Context = args[0] CmdName = args[1] IsAllowed = HonestController.IsThisCommandAllowed( Context.channel, Context.author, CmdName) LOG.info("C:{} M:{} V:{}".format(CmdName, Context.author.name, IsAllowed)) if IsAllowed: await OriginalCommandFuntion(*args, **kwargs) else: await Context.send(BotUtilsLib.GetComamndNotAllowedMsg(CmdName))
async def SetUnsetRole(Context, role_mention, member_mention, SetRole=True): MemberObject = None RoleObject = None #TODO::use dialog here if not "@" in member_mention or not "@" in role_mention: await Context.send( "Please Mention member using @<member_name> and role using @<role_name>" ) else: user_id = BotUtilsLib.GetMemberIDFromMention(member_mention) role_id = BotUtilsLib.GetRoleIDFromMention(role_mention) if user_id == 0: await Context.send("Member Not found!") else: MemberObject = Context.guild.get_member(int(user_id)) RoleObject = Context.guild.get_role(int(role_id)) if SetRole: await MemberObject.add_roles(RoleObject, reason="Changed by Guild-Master") else: await MemberObject.remove_roles(RoleObject, reason="Changed by Guild-Master")
async def SendDialogues(Context, CmdName, Dlg): BotDialoge = "" if Dlg == None: alldlgs = ConfigLib.GetDlgKeys() for sindlg in alldlgs: BotDialoge = BotDialoge + sindlg + "\n" else: BotDialoge = ConfigLib.GetBotDialogue(Dlg.upper()) if BotDialoge: await Context.send(BotDialoge) else: await Context.send( BotUtilsLib.GetBotDialogByKey("DLG_DLG_NOFOUND", MentionMember=Context.author))
async def Attack(Context, AttackName): global IsBattleRunnning global CurrentBoss #TODO::Delete Old Msgs When Battle is running if not IsBattleRunnning: return AttackName = AttackName.lower() AttacksArray = AssetsLib.GetAttacks() AttackFound = False for SingleAttack in AttacksArray: if AttackName == SingleAttack["Name"]: AttackFound = True if not AttackFound: await Context.channel.send( BotUtilsLib.GetBotDialogByKey("DLG_ATK_NOTFOUND", MentionMember=Context.author)) return #TODO::Check Attack Limit Here MemberAttacks = GetMemberAttacks(Context.author) if AttackName in MemberAttacks.keys(): AttackInfo = MemberAttacks[AttackName] Damage = random.randint(AttackInfo["dmgmin"], AttackInfo["dmgmax"]) CurrentBoss["XP"] = CurrentBoss["XP"] - Damage await Context.channel.send(file=discord.File(CurrentBoss["Image"])) await Context.channel.send("HP:" + str(CurrentBoss["XP"])) await Context.channel.send( BotUtilsLib.GetBotDialogByKey( "DLG_ATK_DAMAGE", MentionMember=Context.author) + str(Damage)) else: await Context.channel.send( BotUtilsLib.GetBotDialogByKey("DLG_ATK_NOTAVAIL", MentionMember=Context.author))
async def SayHello(Context, CmdName): HelloMsg = BotUtilsLib.GetBotDialogByKey("DLG_HELLO", MentionMember=Context.author) await Context.send(HelloMsg)
async def OnMemberJoin(bot, MemberObject): welcome_channel = bot.get_channel( ConfigLib.GetChannelIDByAlias("CHNL_WELCOME")) welcome_msg = BotUtilsLib.GetBotDialogByKey("DLG_GREET", MentionMember=MemberObject) await welcome_channel.send(welcome_msg)