async def on_message(self, message: discord.Message): # Chat Money if not isinstance(message.channel, discord.DMChannel): pref: str = get_prefix(message.guild) guild_data: dict = checkin_guild(message.guild) get_money: int = random.randint(guild_data["currency"]["chat-min"], guild_data["currency"]["chat-max"]) await add_money(message.guild.id, message.author, get_money)
async def _make_things(self, ctx: commands.Context, *args): """## Arguments ------------ Insert with the following order: `option`(str) `name`(str). It is optional. ## Options ---------- Move, Item, Equipment """ mbr_data = checkin_member(ctx.author) if mbr_data is not None: if "moves" in mbr_data: if len(args) == 0: await self.__creator_help(ctx.channel) elif len(args) >= 1: gld_data: dict = checkin_guild(ctx.guild) if args[0].lower() == "move" or args[0].lower() == "m": if len(gld_data["shop"] ["movements"]) >= gld_data["max-misc"]["move"]: await ctx.send( "Server already contain full Custom Move. You can't create unless delete one of them." ) else: await self.__make_move_process(ctx.channel, ctx.author, name=" ".join( args[1:])) elif args[0].lower() == "item" or args[0].lower() == "i": if len(gld_data["shop"]["equipments"] ) >= gld_data["max-misc"]["equip"]: await ctx.send( "Server already contain full Custom Move. You can't create unless delete one of them." ) else: await self.__make_item_process(ctx.channel, ctx.author, name=" ".join( args[1:])) elif args[0].lower() == "equipment" or args[0].lower( ) == "eq": if len(gld_data["shop"] ["items"]) >= gld_data["max-misc"]["item"]: await ctx.send( "Server already contain full Custom Move. You can't create unless delete one of them." ) else: await self.__make_eq_process(ctx.channel, ctx.author, name=" ".join( args[1:])) else: await ctx.send( f"__**{ctx.author.name}, You haven't start your character, type {get_prefix(ctx.guild)}start to begin.**__" )
async def detail_money(self, message: discord.Message, person: discord.User): gdata: dict = checkin_guild(message.guild) mbr_data = checkin_member(person) if mbr_data is not None: emb = discord.Embed( description= f"> 👛 Amount : {mbr_data['backpack']['money'][str(message.guild.id)]} {gdata['currency']['type']}", colour=WHITE) emb.set_author(name=person.name, icon_url=person.avatar_url) await message.edit(embed=emb)
async def on_message(self, message: discord.Message): # Ignore DM Channel if isinstance(message.channel, discord.DMChannel): return gld_data = checkin_guild(message.guild) if gld_data["event-channel"] is not None: channel: discord.TextChannel = self.bot.get_channel( int(gld_data["event-channel"])) await add_exp(channel, message.author, 1) else: await add_exp(message.channel, message.author, 1)
async def main_menu(self, message: discord.Message, person: discord.User): tud: dict = checkin_guild(message.guild) menu_emb = discord.Embed( title=f"{message.author.display_name}'s Inventory", description=f"👛 Wallet\n" "⛏️ Ores \n" "🛡️ Equipment\n" "🧳 Backpack Items\n" "🔙 Go Back to Menu", colour=WHITE) menu_emb.set_footer(text="Select Option Below to see the Detail") await message.edit(embed=menu_emb)
async def load_story(self, channel: discord.TextChannel, person: discord.User, *, page: int = 1): stories: list = checkin_guild(channel.guild)["stories"] sum_stacks: int = len(stories) // 10 if len(stories) % 10 == 0 else len(stories) // 10 + 1 # Cut into Several Pages page = sum_stacks if page > sum_stacks else page def emb_maker() -> discord.Embed: desc: str = "```" for s in range((page - 1) * 10, page * 10): if len(stories) > s: desc += f"{s + 1}. {stories[s]['title']}\n" if s != page * 10 - 1 else f"{stories[s]['title']}" else: break desc += "```" emb = discord.Embed( title=f"📚 One Word Story | {channel.guild.name}'s Library", description=desc, colour=WHITE ) emb.set_footer(text=f"Page {page}/{sum_stacks} | {get_prefix(channel.guild.id)}ows -r <num> to Read the Story") return emb if len(stories) <= 0: e = discord.Embed( title=f"📚 One Word Story | {channel.guild.name}'s Library", description="Library is empty. Make your own story now!", colour=WHITE ) e.set_footer(text=f"{get_prefix(channel.guild.id)}ows -p to start making story.") await channel.send(embed=e) else: try: menus: list = ["⬅️", "➡️"] hm: discord.Message = await channel.send(embed=emb_maker()) for i in menus: await hm.add_reaction(i) while True: r: discord.Reaction u: discord.User r, u = await self.bot.wait_for( event="reaction_add", check=lambda reaction, user : True if user == person and str(reaction.emoji) in menus else False, timeout=30.0 ) if str(r.emoji) == "➡️": page += 1 if page < sum_stacks else 0 else: page -= 1 if page > 0 else 0 await r.remove(u) await hm.edit(embed=emb_maker()) except asyncio.TimeoutError: pass
async def _lb(self, ctx: commands.Context): data = db_mbr.FindObject({}, sortby=f"backpack.money.{str(ctx.guild.id)}", limit=5) guid_currency: str = checkin_guild(ctx.guild)['currency']['type'] # Create Description and Send Result members: list = [self.bot.get_user(int(i['member_id'])) for i in data] index_del: list = [] for j in range(len(members)): if members[j] is None: index_del.append(j) for k in range(len(index_del), 0, -1): data.pop(index_del[k - 1]) members.pop(index_del[k - 1]) desc: list = [f"> {p+1}. {members[p].name} : {data[p]['backpack']['money'][str(ctx.guild.id)]} {guid_currency}" for p in range(len(members))] emb = discord.Embed( title="📈 Leaderboard", colour=WHITE ) emb.add_field( name="🏦 Top 5 Richest in Server", value="\n".join(desc), inline=False ) emb.set_thumbnail(url="https://i.dlpng.com/static/png/5698135-trophy-clipart-png-transparent-background-image-free-png-templates-trophy-clipart-png-2000_2000_preview.png") await ctx.send(embed=emb)
async def _one_word_story(self, ctx: commands.Context, *args): list_of_stories: list = checkin_guild(ctx.guild)["stories"] if len(args) == 0: await self.print_help(ctx.channel) else: # Play if args[0].lower() == "-p" or args[0].lower() == "play": await self.ows_on_play(ctx.channel) # Help elif args[0].lower() == "-h" or args[0].lower() == "help": await self.print_help(ctx.channel) # Read Story elif args[0].lower() == "-r": story_num: int = random.randint(1, len(list_of_stories)) if len(args) == 2: isnum: bool = is_number(args[1]) story_num = int(args[1]) if isnum is True else random.randint(1, len(list_of_stories)) picked_story: dict = list_of_stories[story_num - 1] emb = discord.Embed( title=picked_story['title'], description=picked_story['story'], colour=WHITE ) emb.set_footer(text=f"Made on: {picked_story['date-made']}") await ctx.send(embed=emb) # Guild own Story elif args[0].lower() == "-os": if len(args) == 2: isnum: bool = is_number(args[1]) args[1] = int(args[1]) if isnum is True else 1 await self.load_story(ctx.channel, ctx.author, page=args[1]) else: await self.load_story(ctx.channel, ctx.author) # Delete Story elif args[0].lower() == "-del": if len(args) < 2: emb_err =discord.Embed( title="📚 One Word Story | Delete Story", colour=WHITE ) emb_err.add_field( name="How to Use?", value="Use this Command seperated with space and followed by -del and index of story you like to delete." f"Example Command to delete index number 1: {get_prefix(ctx.guild.id)}ows -del 1", inline=False ) await ctx.send(embed=emb_err) else: isnum: bool = is_number(args[1]) if isnum is False: emb_err = discord.Embed( title="📚 One Word Story | Delete Story", colour=WHITE ) emb_err.add_field( name="How to Use?", value="Use this Command seperated with space and followed by -del and index of story you like to delete." f"Example Command to delete index number 1: {get_prefix(ctx.guild.id)}ows -del 1", inline=False ) await ctx.send(embed=emb_err) else: index: int = int(args[1]) - 1 await ctx.send(content= f"Successfully deleted story with title : {list_of_stories[index]['title']}") db_gld.UnsetItem({"guild_id": str(ctx.guild.id)}, {f"stories.{index}": list_of_stories[index]}) db_gld.UpdateObject({"guild_id": str(ctx.guild.id)}, {"$pull": {"stories": None}}) # How to Play elif args[0].lower() == "-how": await self.manual(ctx.channel)
async def _currency(self, ctx: commands.Context, *args): if len(args) == 0: await self.print_help(ctx.channel) else: guild_info: dict = checkin_guild(ctx.guild.id) cur_type: str = guild_info['currency']['type'] person: discord.User = ctx.author # Change Server Currency Type if len(args) == 2 and args[0].lower() == "-t": emoji = check_emoji(args[1]) if emoji: emb: discord.Embed if "\\U" in emoji: partial_emoji = emoji.encode("ASCII").decode("unicode-escape") db_gld.SetObject({"guild_id": str(ctx.guild.id)}, { "currency.type": partial_emoji }) emb = discord.Embed ( title="Server New Currency!", description=f"> Server {ctx.guild.name} Currency is now {partial_emoji}", colour=WHITE ) else: db_gld.SetObject({"guild_id": str(ctx.guild.id)}, { "currency.type": emoji }) emb = discord.Embed ( title="Server New Currency!", description=f"> Server {ctx.guild.name} Currency is now " + emoji, colour=WHITE ) db_gld.SetObject({"guild_id": str(ctx.guild.id)}, { "currency.modif-by": person.name, "currency.last-modified": datetime.datetime.now().strftime('%B %d %Y') }) await ctx.send(embed=emb) # Get Info Currency in Server elif args[0].lower() == "-get": emb = discord.Embed( title=f"🏦 {ctx.guild.name}", description=f"Currency Type : {cur_type}\n" f"Chat Money [min-max] : {guild_info['currency']['chat-min']}-{guild_info['currency']['chat-max']} {cur_type}", colour=WHITE ) emb.set_footer(text=f"Last Modified : {guild_info['currency']['last-modified']} | By : {guild_info['currency']['modif-by']}") await ctx.send(embed=emb) # Set Min Earn Money by Chatting elif len(args) == 2 and args[0].lower() == "-min": isnum: bool = is_number(args[1]) if isnum is True: min_in: int = int(args[1]) if guild_info["currency"]["chat-max"] < min_in: db_gld.SetObject({"guild_id": str(ctx.guild.id)}, { "currency.chat-max": min_in }) db_gld.SetObject({"guild_id": str(ctx.guild.id)}, { "currency.chat-min": min_in }) updated_guild_info: dict = checkin_guild(ctx.guild.id) emb = discord.Embed( title="💸 Set Chat Money Success", description=f"Chat Money Increament : {updated_guild_info['currency']['chat-min']}-{updated_guild_info['currency']['chat-max']}", colour=WHITE ) db_gld.SetObject({"guild_id": str(ctx.guild.id)}, { "currency.modif-by": person.name, "currency.last-modified": datetime.datetime.now().strftime('%B %d %Y') }) await ctx.send(embed=emb) # Set Max Earn Money by Chatting elif len(args) == 2 and args[0].lower() == "-max": isnum: bool = is_number(args[1]) if isnum is True: max_in: int = int(args[1]) if guild_info["currency"]["chat-min"] > max_in: db_gld.SetObject({"guild_id": str(ctx.guild.id)}, { "currency.chat-min": max_in }) db_gld.SetObject({"guild_id": str(ctx.guild.id)}, { "currency.chat-max": max_in }) updated_guild_info: dict = checkin_guild(ctx.guild.id) emb = discord.Embed( title="💸 Set Chat Money Success", description=f"Chat Money Increament : {updated_guild_info['currency']['chat-min']}-{updated_guild_info['currency']['chat-max']}", colour=WHITE ) db_gld.SetObject({"guild_id": str(ctx.guild.id)}, { "currency.modif-by": person.name, "currency.last-modified": datetime.datetime.now().strftime('%B %d %Y') }) await ctx.send(embed=emb)
async def _envent_channel(self, ctx: commands.Context, channel: discord.TextChannel): gld_data = checkin_guild(ctx.guild) db_gld.SetObject({"guild_id": str(ctx.guild.id)}, {"event-channel": str(channel.id)}) await ctx.send(f"Events has been set in channel `{channel.name}`.")
async def _lets_battle(self, channel: discord.TextChannel, t1: list, t2: list): # Inner Functions # it Returns target attack, for default it will return None if not exist # Find Target Attack by Index def find_target_by_index(arg: int, target_team: list, *, move_sample: Movement = None, item_sample=None): """`team` must contains only `Character` object type.""" if arg < 1 or arg > len(target_team): return None # Type Move use if move_sample is not None: # For Single Target, just return the target Character if move_sample.GetTargetID() == 1: return target_team[arg - 1] # For Multiple Target else: # Making sure the target is on the first index, then return a list of target copy_team = target_team.copy() list_target = [copy_team[arg - 1]] del copy_team[arg - 1] return list_target + copy_team return None # Find Target Attack by Name def find_target_by_name(arg: str, target_team: list, *, move_sample: Movement = None, item_sample=None): """`team` must contains only `Character` object type.""" team_names = [n.name for n in target_team] if arg not in team_names: return None # Type Move use if move_sample is not None: # For Single Target, just return the target Character if move_sample.GetTargetID() == 1: return team[team_names.index(arg)] # For Multiple Target else: # Making sure the target is on the first index, then return a list of target copy_team = target_team.copy() list_target = [copy_team[team_names.index(arg)]] del copy_team[team_names.index(arg)] return list_target + copy_team return None def make_emb(): nonlocal target emb = discord.Embed( title="⚔️ Arena ⚔️", description=f"**{turns[index][0].name}, Your Turn!**", colour=WHITE) emb.add_field( name=f"🔴 Red Team | Alive {survivet1}", inline=False, value="\n".join([ f"> {j + 1}. **{t1[j][0].name}** `HP: {t1[j][0].HP}/{t1[j][0].MAX_HP} | MANA: {t1[j][0].MANA}/{t1[j][0].MAX_MANA}`" for j in range(len(t1)) ])) emb.add_field( name=f"🔵 Blue Team | Alive {survivet2}", inline=False, value="\n".join([ f"> {j + 1}. **{t2[j][0].name}** `HP: {t2[j][0].HP}/{t2[j][0].MAX_HP} | MANA: {t2[j][0].MANA}/{t2[j][0].MAX_MANA}`" for j in range(len(t2)) ])) descr: str = "" if get_started is True: descr = "```Empty Log```" else: descr += f"`{char_turn[0].Msg}`\n" if isinstance(target, list): for i in target: descr += f"`{i.Msg}`" else: descr += f"`{target.Msg}`" emb.add_field(name="📄 Battle Log", value=descr, inline=False) emb.set_footer(text="Send move Message in this channel.") return emb # Check user reply usage def check_reply(char: Character, your_team: list, opposition_team: list): nonlocal target def inner_check(message: discord.Message): nonlocal target argument: list or tuple = message.content.split(' ') # 3 Argument beginning with "use" statement if argument[0].lower() == "use" and len( argument) == 3 and message.author.id == char.id: # Specify what do player want to do # Using a normal move from Character if argument[1].lower() == "normal": if is_number(argument[2]): target = find_target_by_index( int(argument[2]), opposition_team, move_sample=char._normal_move) else: target = find_target_by_name( argument[2], opposition_team, move_sample=char._normal_move) # Use Character Normal Move if target is not None: char.NormalAttack(target) return True # Using a custom move from Character elif is_number(argument[1]): if int(argument[1]) >= 1 or int(argument[1]) <= len( char._custom_moves): if is_number(argument[2]): target = find_target_by_index( int(argument[2]), opposition_team, move_sample=char._normal_move) else: target = find_target_by_name( argument[2], opposition_team, move_sample=char._normal_move) # Use Character Normal Move if target is not None: char.CustomAttack(target, int(argument[1])) return True # Using a item from Character # elif (argument[1] in moves or argument[1] in items) and (is_number(argument[2]) or argument[2] in names_in_game): # return True return False return inner_check # Initialize Attribute turns: list = [] get_started: bool = True send_count, index = 0, 0 survivet1: int = len(t1) survivet2: int = len(t2) char_turn = None target = None # Preparing Turns and Teams async with channel.typing(): # For Team 1 (Red Team) for i in t1: while index < len(turns): if i.SPD > turns[index][0].SPD: break index += 1 turns.insert(index, (i, 1)) # 1 means the team id for Red Team index = 0 # For Team 2 (Blue Team) for j in t2: while index < len(turns): if j.SPD > turns[index][0].SPD: break index += 1 turns.insert(index, (j, 2)) # 2 means the team id for Blue Team index = 0 # Send Hint to all PPL and Channel for k in turns: char_user: discord.User = self.bot.get_user(k[0].id) await send_batte_hint(char_user, k[0]) t1 = [(turns[c1][0], c1) for c1 in range(len(turns)) if turns[c1][1] == 1] t2 = [(turns[c2][0], c2) for c2 in range(len(turns)) if turns[c2][1] == 2] hm: discord.Message = await channel.send(embed=make_emb()) # Game ON! try: while True: # Waiting for user to input action # Turn Character, then user need to send action char_turn = turns[index] if char_turn[0].HP == 0: index = (index + 1) if index < len(turns) - 1 else 0 continue # Character from Red Team reply: discord.Message = None if char_turn[1] == 1: reply = await self.bot.wait_for( event="message", timeout=60.0, check=check_reply(char_turn[0], [i[0] for i in t1], [j[0] for j in t2])) # Character from Blue Team else: reply = await self.bot.wait_for( event="message", timeout=60.0, check=check_reply(char_turn[0], [i[0] for i in t2], [j[0] for j in t1])) await reply.delete() async with channel.typing(): # Check Team Completion survivet1 = 0 survivet2 = 0 for pt1 in t1: if pt1[0].HP > 0: survivet1 += 1 for pt2 in t2: if pt2[0].HP > 0: survivet2 += 1 if survivet1 == 0 or survivet2 == 0: break # Edit Hint, Resend Battle Message get_started = False index = (index + 1) if index < len(turns) - 1 else 0 send_count = (send_count + 1) if send_count < 2 else 0 if send_count == 0: await hm.delete() hm = await channel.send(embed=make_emb()) else: await hm.edit(embed=make_emb()) # Send Reward gld_data = checkin_guild(channel.guild) event_channel: discord.TextChannel = self.bot.get_channel( int(gld_data["event-channel"]) ) if gld_data["event-channel"] is not None else channel if survivet1 <= 0: for i in t2: char_user = self.bot.get_user(i[0].id) await add_exp(event_channel, char_user, RewardEXP) await add_money(channel.guild.id, char_user, RewardMoney) for i in t1: char_user = self.bot.get_user(i[0].id) await add_exp( event_channel, char_user, math.ceil(RewardEXP - (RewardEXP * (80 / 100)))) await add_money( channel.guild.id, char_user, math.ceil(RewardMoney - (RewardMoney * (80 / 100)))) emb = discord.Embed( title="🔵 Blue Team Wins!", colour=WHITE, description="\n".join( [f"> {winner[0].name}" for winner in t2]), ) emb.add_field( name="Reward :", inline=False, value= f"EXP: {RewardEXP} | Money: {RewardMoney} {checkin_guild(channel.guild)['currency']['type']}" ) await channel.send(embed=emb) else: for i in t1: char_user = self.bot.get_user(i[0].id) await add_exp(event_channel, char_user, RewardEXP) await add_money(channel.guild.id, char_user, RewardMoney) for i in t2: char_user = self.bot.get_user(i[0].id) await add_exp( event_channel, char_user, math.ceil(RewardEXP - (RewardEXP * (80 / 100)))) await add_money( channel.guild.id, char_user, math.ceil(RewardMoney - (RewardMoney * (80 / 100)))) emb = discord.Embed(title="🔴 Red Team Wins!", description="\n".join([ f"> {winner[0].name}" for winner in t1 ]), colour=WHITE) emb.add_field( name="Reward :", inline=False, value= f"EXP: {RewardEXP} | Money: {RewardMoney} {checkin_guild(channel.guild)['currency']['type']}" ) await channel.send(embed=emb) # Delete Cooldown await self._cooling_down(channel.channel.id) except asyncio.TimeoutError: await hm.delete(delay=1) await channel.send( f"*Gameplay turn Timeout! {char_turn[0].name}, where have you been?*" ) await self._cooling_down(channel.id)
async def _learn(self, ctx: commands.Context, page: int = 1): mbr_data = checkin_member(ctx.author) if mbr_data is not None: if "moves" in mbr_data: if len(mbr_data["moves"]) < 3: gld_data = checkin_guild(ctx.guild) # No Moves Available if len(gld_data["shop"]["movements"]) == 0: emb = discord.Embed( title=f"No Moves Available in {ctx.guild.name}", description= f"Create your first custom move, type `{get_prefix(ctx.guild)}create move` to make it up.", colour=WHITE) await ctx.send(embed=emb) # There are moves in the guild else: move_data: list = gld_data["shop"]["movements"] menu = ["⬅️", "✅", "🚫", "➡️"] emb = embed_move_maker(move_data[page - 1]) emb.set_footer( text= "React with ✅ to learn this Move or 🚫 to abort.") hm: discord.Message = await ctx.send(embed=emb) for i in menu: await hm.add_reaction(i) try: while True: r, u = await self.bot.wait_for( event="reaction_add", timeout=30.0, check=lambda reaction, user: True if str(reaction.emoji) in menu and user == ctx.author else False) await hm.remove_reaction(str(r.emoji), u) # Accept Training if str(r.emoji) == "✅": for j in menu: await hm.remove_reaction(j, ctx.me) db_mbr.UpdateObject( {"member_id": str(ctx.author.id)}, { "$push": { "moves": move_data[page - 1] } }) await hm.edit( content= f"{ctx.author.mention} learned `{move_data[page - 1]['NAME']}`." ) break # Abort Training elif str(r.emoji) == "🚫": await hm.edit(content="*Action Aborted*") break # Next Page elif str(r.emoji) == "➡️": page = page + 1 if page < len( move_data) else 1 # Previous Page elif str(r.emoji) == "⬅️": page = page - 1 if page > 0 else len( move_data) # Edit Message Input emb = embed_move_maker(move_data[page - 1]) emb.set_footer( text= "React with ✅ to learn this Move or 🚫 to abort." ) await hm.edit(embed=emb) except asyncio.TimeoutError: await hm.edit(content="*Request Timeout*") else: await ctx.send( f"__**{ctx.author.name}, You haven't start your character, type {get_prefix(ctx.guild)}start to begin.**__" )