async def rps(ctx, *, level=1): if level > RPS_HARD_CAP and not isOwner(ctx): msg = add_to_embed('Level too high!', f'Sorry, but even though the code for it exists, why would you ever want to play rps-{level*2+1}???')[0] msg.set_footer(text='RPS Played by: ' + ctx.author.name, icon_url=ctx.author.avatar_url) await ctx.send(embed=msg) return symbol_names = ['rock','paper','scissors','spock','lizard','alien','well','generic','karen','heat','lemonade'] # Extend symbol names if necessary for i in range(len(symbol_names), level*2+5): symbol_names.append('item'+str(i)) # Generate matrix matrix = gen_rps_matrix(level) # Ask for user choice color = None embed = add_to_embed(f'{ctx.author.name}\'s RPS','Pick an option:\nrules'+'\n'.join(symbol_names[:level*2+1]))[0] color = embed.color await ctx.send(embed=embed) # Get user choice def check(m): return m.author == ctx.author and m.channel == ctx.channel try: msg = await bot.wait_for('message', check=check,timeout=1*60) except: embed = add_to_embed(f'{ctx.author.name}\'s RPS','Awww, don\'t leave me hangin\'')[0] embed.set_footer(text='RPS Played by: ' + ctx.author.name, icon_url=ctx.author.avatar_url) await ctx.channel.send(embed=embed) return freeform = msg.content.lower().replace(' ','_').replace('\n','') # Process winner mlo = getClosestFromList(['rules']+symbol_names,freeform) output = '' if 'rules' in mlo: output = ' \n'.join(format_matrix(matrix, symbol_names)) elif distance(freeform, mlo) >= len(freeform)*0.3: #If the most likely option is more than 30% wrong, hassle output = 'No option recognized! Your choices are: '+'\n'.join(['rules']+symbol_names[:level*2+1]) else: choice = symbol_names.index(getClosestFromList(symbol_names, freeform)) computer_choice = random.randint(0, len(matrix[0])-1) winner = matrix[choice][computer_choice] if winner == 0: output = "Its a draw! Better luck next time" elif winner == 1: output = "You win. Nice job. 🥳" elif winner == 2: output = "I win ;) Better luck next time" output = output+"\n\nYou chose "+ symbol_names[choice]+"\nI chose "+symbol_names[computer_choice] embed = add_to_embed(f'{ctx.author.name}\'s RPS', output)[0] if color != None: embed.color = color embed.set_footer(text='RPS Played by: ' + ctx.author.name, icon_url=ctx.author.avatar_url) await ctx.send(embed=embed)
async def userinfo(ctx, user:discord.User=None): if not ctx.author.guild_permissions.administrator and not isOwner(ctx): await ctx.send(f'You must be an owner or a server administrator', hidden=True) return x = ctx.guild.members roles = [role for role in user.roles[1:]] embed = discord.Embed(title="User information", colour=discord.Color.gold(), timestamp= datetime.fromtimestamp(time.time())) embed.set_author(name=user.name, icon_url=user.avatar_url) embed.set_thumbnail(url=user.avatar_url) embed.set_footer(text='Info Requested by: ' + ctx.author.name, icon_url=ctx.author.avatar_url) #this checks if the user has no roles it will say they have no roles listRoles = "User has no roles" if len(roles) != 0: listRoles = " ".join([role.mention for role in roles]) fields = [("Name", str(user), False), ("Status", user.raw_status, False), (f"Roles ({len(roles)})", listRoles , False), ("Created at", user.created_at.strftime("%d/%m/%Y %H:%M:%S"), False), ("Joined at", user.joined_at.strftime("%d/%m/%Y %H:%M:%S"), False)] for name, value, inline in fields: embed.add_field(name=name, value=value, inline=inline) await ctx.send(embed=embed)
async def off(ctx): if(isOwner(ctx)): await ctx.send(msgReturn("offMsg")) await bot.close() sys.exit(0) else: await ctx.send(msgReturn("notOwner"))
async def space(ctx, message:str='', amount:int=1): exp_len = (len(message)-1)*amount + len(message) if not isOwner(ctx) and exp_len >= SPACE_LEN_HARD_CAP: await ctx.send('That message would be {0} characters, waaaay higher than the limit of {1}. Chill.'.format(exp_len, SPACE_LEN_HARD_CAP)) return to_send = (' '*max(1, amount)).join(message) for message in splitLongStrings(to_send): await ctx.send(message)
async def shrek(ctx, *, embed:bool=False): if not isOwner(ctx): await ctx.send(msgReturn("notOwner")) return with open('Shrek.txt', 'r') as file: shrek = file.read() if embed: for embed in add_to_embed('Shrek is love, Shrek is life', shrek.replace('\n\n','\n')): embed.color = discord.Colour(imgutils.randomSaturatedColor()) await ctx.send(embed=embed) else: for message in splitLongStrings(shrek): await ctx.send(message.replace('\n\n','\n'))
async def servers(ctx): #cheks if your owner if not isOwner(ctx): await ctx.send(msgReturn('notOwner')) return msg = '' #gets all the servers from bot object guilds = await bot.fetch_guilds(limit=150).flatten() msg = str(len(guilds)) + '\n' #loops through them and puts them in a string for i in guilds: msg += i.name + '\n' #creates a dm with user and dms it to them author = ctx.author await author.send(msg) await ctx.send("Please check your DM's")
async def status(ctx, type:str='', URL:str='https://twitch.tv/saiencevanadium/'): if not isOwner(ctx): await ctx.send(msgReturn('notOwner')) return if(type.lower() == 'help'): await bot.change_presence(activity=discord.Game(name='with his food | /help')) elif(type.lower() == 'music'): currActicity = ctx.author.activities #find where the activity is in the tuple for i in range(len(currActicity)): if(after.activities[i].type is discord.ActivityType.streaming): await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=ctx.author.activities[i].title)) else: await ctx.send("Sorry but you are not listening to music.", hidden=True) elif(type.lower() == 'watching'): await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=URL)) await ctx.send('Status updated', hidden=True)
async def sendDM(ctx, user:discord.User=None, message:str=''): if not isOwner(ctx): await ctx.send(msgReturn("notOwner")) return await user.send(message) await ctx.send("Message has safely been sent.")
async def roll(ctx, dice:str='1d6'): if isOwner(ctx): ctx.defer() # I solemnly swear that I am up to no good MAXROLLS = 20 MAXSIDES = 100 dice = dice.upper() r_data = [] print(dice) async def senderr(msg=''): msg = f'\n{msg}' if len(msg) > 0 else '' embed = discord.Embed(title='Input was Invalid', description=f'The command was used incorrectly it is used like `/roll` or `/roll 2d4`{msg}') embed.set_footer(text=f'Command used inproperly by: {ctx.author.name} (args: {dice})', icon_url=ctx.author.avatar_url) await ctx.send(embed=embed) def rollone(rolls, sides): total, txt = 0, "" for i in range(rolls): x = random.randint(1,sides) txt += f'{x}, ' total += x return total, txt[:-2] if rolls > 0 else "" if(dice.find('D') == -1): try: r_data = [int(dice), 6] except ValueError: await senderr() return else: try: r_data = [int(x) for x in dice.split('D')] except ValueError: await senderr() return dice = 'd'.join([str(x) for x in r_data]) grand_total, msg = 0, '' while len(r_data) > 1: rolls, sides = r_data[:2] if isOwner(ctx) or (0 < rolls <= MAXROLLS and 1 < sides <= MAXSIDES): total, out = rollone(rolls, sides) grand_total += total out = f'{rolls}d{sides}: {out}' # add dice total on if this isn't the last iteration if len(r_data) > 2 and rolls > 1: out = f'{out} (total: {total})' # add to msg with fenceposting msg = f'{msg}\n{out}' if len(msg) > 0 else out # shorten list r_data.pop(0) r_data[0] = total else: await senderr(f'{msg}\nYou have reached the limits. Make sure you roll less than {MAXROLLS} dice and each dice has less than {MAXSIDES} sides') return embed = discord.Embed(title=str(dice), description=f'{msg}\n\nTotal: {total}', colour=imgutils.randomSaturatedColor()) embed.set_footer(text=f'{dice} was rolled by: ' + ctx.author.name, icon_url=ctx.author.avatar_url) await ctx.send(embed=embed)
async def rpsc(ctx, user:discord.User=None, level:int=1): if level > RPS_HARD_CAP and not isOwner(ctx): msg = add_to_embed('Level too high!', f'Sorry, but even though the code for it exists, why would you ever want to play rps-{level*2+1}???')[0] msg.set_footer(text='RPS Played by: ' + ctx.author.name, icon_url=ctx.author.avatar_url) await ctx.send(embed=msg) return symbol_names = ['rock','paper','scissors','spock','lizard','alien','well','generic','karen','heat','lemonade'] # Extend symbol names if necessary for i in range(len(symbol_names),level*2+5): symbol_names.append('item'+str(i)) # Generate matrix matrix = gen_rps_matrix(level) msg = 'You are challenging '+user.name+' to rock-paper-scissors' if level > 1: msg = msg+'-'+str(level*2+1) embed = add_to_embed(f'Your challenge to {user.name}',msg+'\nCheck your DMs!')[0] embed.set_footer(text='Challenge sent by: ' + ctx.author.name, icon_url=ctx.author.avatar_url) await ctx.send(embed=embed) def get_check(user): def check(msg): return msg.author == user and msg.channel == user.dm_channel return check async def get_response(_user, title='RPSC', timeout=10*60, opener=''): choice = symbol_names[0] i = 0 while i < 3: i += 1 for msg in add_to_embed(title, f'{opener}Your choices are '+', '.join(symbol_names[:2*level+1]+['rules','abort'])): await _user.send(embed=msg) opener = '' try: msg = await bot.wait_for('message', check=get_check(_user),timeout=timeout) except: await _user.send(embed=add_to_embed(title, f'Awww, {_user.name} don\'t leave me hangin\'')[0]) return -1 # Abort challenge if you don't send an answer response = msg.content.lower().replace(' ','_').replace('\n','') choice = getClosestFromList(['abort','rules']+symbol_names,response.lower()) if distance(response, choice) >= len(response)*0.3: await _user.send(embed=add_to_embed(choice, 'No option recognized, try again')) if 'abort' in choice.lower(): return -1 if 'rules' in choice.lower(): for msg in add_to_embed(title, ' \n'.join(format_matrix(matrix, symbol_names))): await _user.send(embed=msg) i -= 1 else: # If neither rules or abort, it is correct break return choice # Get your response your_choice = await get_response(ctx.author, title=f'Your challenge to {user.name}') if your_choice == -1: await ctx.author.send(embed=add_to_embed(f'Your challenge to {user.name}', 'Challenge cancelled!')[0]) await ctx.channel.send(embed=add_to_embed(f'{ctx.author.name}\'s challenge', 'Challenge cancelled!')[0]) return your_choice = symbol_names.index(your_choice) await ctx.author.send(embed=add_to_embed(f'Your challenge to {user.name}',f'You chose {symbol_names[your_choice]}')[0]) # Get other person's response #await user.send(embed=add_to_embed('Rock-Paper-Scissors Challenge!', f'{ctx.message.author.name} has challenged you to rock-paper-scissors-'+str(level*2+1) if level > 1 else '')[0]) enemy_choice = await get_response(user, title=f'{ctx.author.name}\'s challenge', opener=f'{ctx.author.name} has challenged you to rock-paper-scissors-'+str(level*2+1) if level > 1 else '') if enemy_choice == -1: embed = add_to_embed(f'{ctx.author.name}\'s challenge', 'Challenge cancelled!')[0] await user.send(embed=embed) await ctx.channel.send(embed=embed) await ctx.author.send(embed=add_to_embed(f'Your challenge to {user.name}', 'Challenge cancelled by opponent')[0]) return enemy_choice = symbol_names.index(enemy_choice) await user.send(embed=add_to_embed(f'{ctx.author.name}\'s challenge', f'You chose {symbol_names[enemy_choice]}')[0]) msg = "" # Display results msg = f'{ctx.author.name} chose {symbol_names[your_choice]}' msg += f'\n{user.name} chose {symbol_names[enemy_choice]}' winner = matrix[enemy_choice][your_choice] if winner == 0: await ctx.author.send(embed=add_to_embed(f'Your challenge to {user.name}', msg.replace(ctx.author.name,'You')+'\nThe bout ended in a draw')[0]) await user.send(embed=add_to_embed(f'{ctx.author.name}\'s challenge', msg.replace(user.name,'You')+'\nThe bout ended in a draw')[0]) msg += '\nThe bout ended in a draw' elif winner == 1: await ctx.author.send(embed=add_to_embed(f'Your challenge to {user.name}', msg.replace(ctx.author.name,'You')+'\nYou won 🥳')[0]) await user.send(embed=add_to_embed(f'{ctx.author.name}\'s challenge', msg.replace(user.name,'You')+'\nYou lost.')[0]) msg += f'\n{ctx.author.name} won! 🥳' elif winner == 2: await ctx.author.send(embed=add_to_embed(f'Your challenge to {user.name}', msg.replace(ctx.author.name,'You')+'\nYou lost')[0]) await user.send(embed=add_to_embed(f'{ctx.author.name}\'s challenge', msg.replace(user.name,'You')+'\nYou won 🥳')[0]) msg += f'\n{user.name} won. Nice job. 🥳' embed = add_to_embed(f'{ctx.author.name}\'s challenge to {user.name}', msg)[0] embed.set_footer(text='RPS Played by: ' + ctx.author.name, icon_url=ctx.author.avatar_url) await ctx.send(embed=embed)
async def test(ctx): if not isOwner(ctx): return await ctx.send(ctx.author.status) await ctx.send(ctx.author.activities) await ctx.send(ctx.author.activity)