Facebook
From Melodic Leech, 3 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 58
  1. import discord
  2. from discord.ext import commands
  3. import asyncio
  4. import random
  5. import time
  6. import config
  7. import pymongo
  8. from pymongo import MongoClient, ReturnDocument
  9.  
  10. cluster = MongoClient(config.MONGOURI)
  11. db = cluster['crymebot']
  12. collection = db['matchmaking']
  13.  
  14. client = commands.Bot(command_prefix = config.PREFIX, help_command=None)
  15.  
  16.  
  17. @client.event
  18. async def on_ready():
  19.     print("Bot is online!")
  20.     game = discord.Game("*arenahelp")
  21.     await client.change_presence(activity=game)
  22.  
  23.  
  24. #start of moderation code
  25. @client.command()
  26. @commands.has_role("Staff")
  27. async def mute(ctx, member: discord.Member, *, Reason = None):
  28.     channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
  29.     role = discord.utils.get(ctx.guild.roles, name = "Jester")
  30.     role2 = discord.utils.get(ctx.guild.roles, name = "Member")
  31.     role3 = discord.utils.get(ctx.guild.roles, name = "日本人")
  32.     role4 = discord.utils.get(ctx.guild.roles, name = "Europe")
  33.     user = ctx.message.author
  34.     await member.add_roles(role)
  35.     await member.remove_roles(role2)
  36.     await member.remove_roles(role3)
  37.     await channel.send(f'{member} has been muted.\nReason: {Reason}')
  38.     await member.send(f'You have been muted by {user}\nReason: {Reason}')
  39.  
  40.  
  41. @client.command()
  42. @commands.has_role("Staff")
  43. async def unmute(ctx, member: discord.Member, *, Reason = None):
  44.     channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
  45.     role = discord.utils.get(ctx.guild.roles, name = "Jester")
  46.     role2 = discord.utils.get(ctx.guild.roles, name = "Member")
  47.     user = ctx.message.author
  48.     await member.add_roles(role2)
  49.     await member.remove_roles(role)
  50.     await channel.send(f'{member} has been unmuted by {user}.\nReason: {Reason}')
  51.     await member.send(f'You have been unmuted please do not repeat the same offense')
  52.  
  53.  
  54. @client.command()
  55. @commands.has_role("Staff")
  56. async def warn(ctx, member: discord.Member, *,reason=None):
  57.     channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
  58.     staff= ctx.message.author
  59.     await member.send(f"You've been warned by {staff}\nReason: {reason}\nIf you continue in engaging in this behavior further disciplinary action will be taken.")
  60.     await channel.send(f'{member} has been issued a warning. \nReason: {reason}')
  61.  
  62.  
  63. @client.command()
  64. @commands.has_role("Staff")
  65. async def send(ctx, member: discord.Member, *, message=None):
  66.     await member.send(f'{message}')
  67.  
  68.  
  69. @client.command()
  70. @commands.has_role('Staff')
  71. async def kick(ctx, member: discord.Member, *, reason = "No reason has been given"):
  72.     channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
  73.     await member.kick(reason=reason)
  74.     await channel.send(f'{member} has been kicked from the server.\nReason: {reason}.')
  75.     await member.send(f'You have been kicked.\n{reason}')
  76.  
  77.  
  78. @client.command()
  79. @commands.has_role('Staff')
  80. async def ban(ctx, userId: int, *, reason= "No reason has been provided"):
  81.     channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
  82.     author = ctx.message.author
  83.     user = discord.Object(userId)
  84.     try:
  85.         await ctx.guild.ban(user)
  86.     except discord.errors.NotFound:
  87.         await ctx.channel.send(f'{userId} not found')
  88.         return
  89.     await channel.send(f'{user} has been banned by {author}.\nReason: {reason}')
  90.  
  91.  
  92. @client.command()
  93. @commands.has_role('Staff')
  94. async def clear(ctx, amount=1):
  95.     await ctx.channel.purge(limit=amount + 1 )
  96.  
  97.  
  98. #start of matchmaking commmands
  99. @client.command()
  100. async def arenahelp(ctx):
  101.     author = ctx.message.author
  102.     await author.send("***arena <ArenaID> <Password> <opponent>**")
  103.  
  104.  
  105. @client.command()
  106. async def arena(ctx, ID, PASS, member: discord.Member):
  107.     author = ctx.message.author
  108.     guild = ctx.message.guild
  109.     roll1 = random.randint(1,6)
  110.     roll2 = random.randint(1,6)
  111.     name = 'Matchmaking'
  112.     category = discord.utils.get(ctx.guild.categories, name=name)
  113.     channel = await guild.create_text_channel(f'{author.id}', category = category)
  114.     embed = discord.Embed(
  115.         title = f'{author} arena',
  116.     )
  117.     embed.set_image( url = "https://cdn.discordapp.com/attachments/647064695487856643/647064925679779840/Jjj8iy7.png")
  118.     embed.add_field(name = "**ArenaID**", value = (ID), inline = False)
  119.     embed.add_field(name = "**Password**", value = (PASS), inline = True)
  120.     embed.set_thumbnail(url = "https://cdn.discordapp.com/attachments/597260087588814848/647107613846405120/Logo_SnR_simple_.png")
  121.     embed.set_footer(text=  "Legal maps and stages")
  122.     await channel.send(f'{member.mention} vs {author.mention}')
  123.    
  124.     await channel.send(embed=embed)
  125.     await channel.send("**After the winner of the set is determined may the winner please post the score in the following format:**\n`(name of winner)(matches won)-(name of loser) (matches lost)`")
  126.     await channel.send("Once you are done the creator of the arena must use *close @<nameofwinner> @<nameofloser> Score")
  127.     if roll1 > roll2:
  128.         await channel.send(f'**{member} has rolled higher and shall ban first**')
  129.     if roll1 < roll2:
  130.         await channel.send(f'**{author} has rolled higher and shall ban first **')
  131.  
  132.  
  133. @client.command()
  134. async def close(ctx, winner: discord.Member, loser: discord.Member, *, score):
  135.     channel = discord.utils.get(ctx.guild.text_channels, name = f'{ctx.message.author.id}')
  136.     await channel.delete()
  137.     embed = discord.Embed(title = f'{winner} vs {loser}')
  138.     embed.set_thumbnail(url = "https://cdn.discordapp.com/attachments/597260087588814848/647107613846405120/Logo_SnR_simple_.png")
  139.     embed.add_field(name = 'Final score', value = f'{score}')
  140.     embed.add_field(name = 'Winner', value = f'{winner}')
  141.     channel = discord.utils.get(ctx.guild.text_channels, name = 'ladder-results')
  142.     await channel.send(embed=embed)
  143.  
  144.     winnersPoints = collection.find_one_and_update( {'_id': (winner.id) } , {'$inc': {'points': 1}, '$set': {'name': f'{winner.name}#{winner.discriminator}'}}, upsert = True, return_document=ReturnDocument.AFTER)['points']
  145.     await addRank(ctx, winner, winnersPoints)
  146.  
  147.     oldPoints = collection.find_one({ '_id': loser.id })
  148.     if oldPoints is None:
  149.         losersPoints = 0
  150.         collection.insert_one({ '_id': loser.id, 'name': f'{loser.name}#{loser.discriminator}', 'points': 0 })
  151.     elif oldPoints['points'] <= 0:
  152.         losersPoints = 0
  153.     else:
  154.         losersPoints = collection.find_one_and_update({'_id': (loser.id) }, {'$inc': {'points': -1}, '$set': {'name': f'{loser.name}#{loser.discriminator}'}}, upsert = True, return_document=ReturnDocument.AFTER)['points']
  155.     await addRank(ctx, loser, losersPoints)
  156.  
  157.  
  158. async def addRank(ctx, member: discord.Member, points):
  159.     roles = ['Bronze', 'Silver', 'Gold', 'Platinum', 'Diamond']
  160.     for x in roles:
  161.         role = discord.utils.get(ctx.guild.roles, name = x)
  162.         await member.remove_roles(role)
  163.     if points == 0:
  164.         await member.send(f"Current score: 0\nCurrent rank: None")
  165.         return
  166.     elif points > 0 and points < 5:
  167.         rank = 'Bronze'
  168.     elif points >= 5 and points < 15:
  169.         rank = 'Silver'
  170.     elif points >= 15 and points < 35:
  171.         rank = 'Gold'
  172.     elif points >= 35 and points < 60:
  173.         rank = 'Platinum'
  174.     elif points >= 60:
  175.         rank = 'Diamond'
  176.     role2 = discord.utils.get(ctx.guild.roles, name = rank)
  177.     await member.add_roles(role2)
  178.     await member.send(f"Current score: {points}\nCurrent rank: {rank}")
  179.  
  180.  
  181. #help command
  182. @client.command()
  183. @commands.has_role('Staff')
  184. async def help(ctx):
  185.     await ctx.send ("Here is a list of my commands: \n**kick** - to kick members the server, they can return if they have a link. \n**ban**- To ban members so they cannot return to the server.\n**clear** - to clear chats. \n**warn** - Warns a user. \n**mute** - Adds the Jester role to a user and removes the member role. \n**unmute** - Removes the jester role and adds the member role.")
  186.  
  187.  
  188. @client.command()
  189. async def hitbox(ctx, name: str, move: str):
  190.     labels = ["Base Knockback", "Angle", "Damage", "Knockback Growth", "Frame", "FAF", "Self Damage"]
  191.     try:
  192.         data = config.hitboxData[name][move]
  193.     except KeyError:
  194.         await ctx.send("Invalid character or move name")
  195.         return
  196.  
  197.     embed = discord.Embed(color=0x7289da)
  198.     for i in range(7):
  199.         embed.add_field(name=labels[i], value=data[i])
  200.     embed.set_footer(text="Hitbox made by " + data[7])
  201.     embed.set_image(url=data[8])
  202.     await ctx.send(embed=embed)
  203.  
  204.  
  205. #meme commands
  206. @client.command()
  207. async def reminder(ctx, num: (float or int), t_f, *, reminder):
  208.     if t_f == "h":
  209.         await ctx.send('reminder has been set!')
  210.         time = (num * 3600)
  211.         await asyncio.sleep(time)
  212.         author = ctx.message.author
  213.         await ctx.send(f'{author.mention}: {reminder}')
  214.     elif t_f == "s":
  215.         await ctx.send('reminder has been set!')
  216.         time = num
  217.         await asyncio.sleep(time)
  218.         author = ctx.message.author
  219.         await ctx.send(f'{author.mention}: {reminder}')
  220.     elif t_f == "m":
  221.         await ctx.send('reminder has been set!')
  222.         time = (num * 60)
  223.         await asyncio.sleep(time)
  224.         author = ctx.message.author
  225.         await ctx.send(f'{author.mention}: {reminder}')
  226.  
  227.  
  228. @client.command()
  229. async def leaderboard(ctx):
  230.     board = collection.find({ }).limit(10).sort('points', pymongo.DESCENDING)
  231.     msg = ""
  232.     for idx, player in enumerate(board, start=1):
  233.         msg += f'#{idx}  Name: {player.get("name")}  Points: {player.get("points")}\n'
  234.     await ctx.send(msg)
  235.  
  236.  
  237. client.run(config.TOKEN)import discord
  238. from discord.ext import commands
  239. import asyncio
  240. import random
  241. import time
  242. import config
  243. import pymongo
  244. from pymongo import MongoClient, ReturnDocument
  245.  
  246. cluster = MongoClient(config.MONGOURI)
  247. db = cluster['crymebot']
  248. collection = db['matchmaking']
  249.  
  250. client = commands.Bot(command_prefix = config.PREFIX, help_command=None)
  251.  
  252.  
  253. @client.event
  254. async def on_ready():
  255.     print("Bot is online!")
  256.     game = discord.Game("*arenahelp")
  257.     await client.change_presence(activity=game)
  258.  
  259.  
  260. #start of moderation code
  261. @client.command()
  262. @commands.has_role("Staff")
  263. async def mute(ctx, member: discord.Member, *, Reason = None):
  264.     channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
  265.     role = discord.utils.get(ctx.guild.roles, name = "Jester")
  266.     role2 = discord.utils.get(ctx.guild.roles, name = "Member")
  267.     role3 = discord.utils.get(ctx.guild.roles, name = "日本人")
  268.     role4 = discord.utils.get(ctx.guild.roles, name = "Europe")
  269.     user = ctx.message.author
  270.     await member.add_roles(role)
  271.     await member.remove_roles(role2)
  272.     await member.remove_roles(role3)
  273.     await channel.send(f'{member} has been muted.\nReason: {Reason}')
  274.     await member.send(f'You have been muted by {user}\nReason: {Reason}')
  275.  
  276.  
  277. @client.command()
  278. @commands.has_role("Staff")
  279. async def unmute(ctx, member: discord.Member, *, Reason = None):
  280.     channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
  281.     role = discord.utils.get(ctx.guild.roles, name = "Jester")
  282.     role2 = discord.utils.get(ctx.guild.roles, name = "Member")
  283.     user = ctx.message.author
  284.     await member.add_roles(role2)
  285.     await member.remove_roles(role)
  286.     await channel.send(f'{member} has been unmuted by {user}.\nReason: {Reason}')
  287.     await member.send(f'You have been unmuted please do not repeat the same offense')
  288.  
  289.  
  290. @client.command()
  291. @commands.has_role("Staff")
  292. async def warn(ctx, member: discord.Member, *,reason=None):
  293.     channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
  294.     staff= ctx.message.author
  295.     await member.send(f"You've been warned by {staff}\nReason: {reason}\nIf you continue in engaging in this behavior further disciplinary action will be taken.")
  296.     await channel.send(f'{member} has been issued a warning. \nReason: {reason}')
  297.  
  298.  
  299. @client.command()
  300. @commands.has_role("Staff")
  301. async def send(ctx, member: discord.Member, *, message=None):
  302.     await member.send(f'{message}')
  303.  
  304.  
  305. @client.command()
  306. @commands.has_role('Staff')
  307. async def kick(ctx, member: discord.Member, *, reason = "No reason has been given"):
  308.     channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
  309.     await member.kick(reason=reason)
  310.     await channel.send(f'{member} has been kicked from the server.\nReason: {reason}.')
  311.     await member.send(f'You have been kicked.\n{reason}')
  312.  
  313.  
  314. @client.command()
  315. @commands.has_role('Staff')
  316. async def ban(ctx, userId: int, *, reason= "No reason has been provided"):
  317.     channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
  318.     author = ctx.message.author
  319.     user = discord.Object(userId)
  320.     try:
  321.         await ctx.guild.ban(user)
  322.     except discord.errors.NotFound:
  323.         await ctx.channel.send(f'{userId} not found')
  324.         return
  325.     await channel.send(f'{user} has been banned by {author}.\nReason: {reason}')
  326.  
  327.  
  328. @client.command()
  329. @commands.has_role('Staff')
  330. async def clear(ctx, amount=1):
  331.     await ctx.channel.purge(limit=amount + 1 )
  332.  
  333.  
  334. #start of matchmaking commmands
  335. @client.command()
  336. async def arenahelp(ctx):
  337.     author = ctx.message.author
  338.     await author.send("***arena <ArenaID> <Password> <opponent>**")
  339.  
  340.  
  341. @client.command()
  342. async def arena(ctx, ID, PASS, member: discord.Member):
  343.     author = ctx.message.author
  344.     guild = ctx.message.guild
  345.     roll1 = random.randint(1,6)
  346.     roll2 = random.randint(1,6)
  347.     name = 'Matchmaking'
  348.     category = discord.utils.get(ctx.guild.categories, name=name)
  349.     channel = await guild.create_text_channel(f'{author.id}', category = category)
  350.     embed = discord.Embed(
  351.         title = f'{author} arena',
  352.     )
  353.     embed.set_image( url = "https://cdn.discordapp.com/attachments/647064695487856643/647064925679779840/Jjj8iy7.png")
  354.     embed.add_field(name = "**ArenaID**", value = (ID), inline = False)
  355.     embed.add_field(name = "**Password**", value = (PASS), inline = True)
  356.     embed.set_thumbnail(url = "https://cdn.discordapp.com/attachments/597260087588814848/647107613846405120/Logo_SnR_simple_.png")
  357.     embed.set_footer(text=  "Legal maps and stages")
  358.     await channel.send(f'{member.mention} vs {author.mention}')
  359.    
  360.     await channel.send(embed=embed)
  361.     await channel.send("**After the winner of the set is determined may the winner please post the score in the following format:**\n`(name of winner)(matches won)-(name of loser) (matches lost)`")
  362.     await channel.send("Once you are done the creator of the arena must use *close @<nameofwinner> @<nameofloser> Score")
  363.     if roll1 > roll2:
  364.         await channel.send(f'**{member} has rolled higher and shall ban first**')
  365.     if roll1 < roll2:
  366.         await channel.send(f'**{author} has rolled higher and shall ban first **')
  367.  
  368.  
  369. @client.command()
  370. async def close(ctx, winner: discord.Member, loser: discord.Member, *, score):
  371.     channel = discord.utils.get(ctx.guild.text_channels, name = f'{ctx.message.author.id}')
  372.     await channel.delete()
  373.     embed = discord.Embed(title = f'{winner} vs {loser}')
  374.     embed.set_thumbnail(url = "https://cdn.discordapp.com/attachments/597260087588814848/647107613846405120/Logo_SnR_simple_.png")
  375.     embed.add_field(name = 'Final score', value = f'{score}')
  376.     embed.add_field(name = 'Winner', value = f'{winner}')
  377.     channel = discord.utils.get(ctx.guild.text_channels, name = 'ladder-results')
  378.     await channel.send(embed=embed)
  379.  
  380.     winnersPoints = collection.find_one_and_update( {'_id': (winner.id) } , {'$inc': {'points': 1}, '$set': {'name': f'{winner.name}#{winner.discriminator}'}}, upsert = True, return_document=ReturnDocument.AFTER)['points']
  381.     await addRank(ctx, winner, winnersPoints)
  382.  
  383.     oldPoints = collection.find_one({ '_id': loser.id })
  384.     if oldPoints is None:
  385.         losersPoints = 0
  386.         collection.insert_one({ '_id': loser.id, 'name': f'{loser.name}#{loser.discriminator}', 'points': 0 })
  387.     elif oldPoints['points'] <= 0:
  388.         losersPoints = 0
  389.     else:
  390.         losersPoints = collection.find_one_and_update({'_id': (loser.id) }, {'$inc': {'points': -1}, '$set': {'name': f'{loser.name}#{loser.discriminator}'}}, upsert = True, return_document=ReturnDocument.AFTER)['points']
  391.     await addRank(ctx, loser, losersPoints)
  392.  
  393.  
  394. async def addRank(ctx, member: discord.Member, points):
  395.     roles = ['Bronze', 'Silver', 'Gold', 'Platinum', 'Diamond']
  396.     for x in roles:
  397.         role = discord.utils.get(ctx.guild.roles, name = x)
  398.         await member.remove_roles(role)
  399.     if points == 0:
  400.         await member.send(f"Current score: 0\nCurrent rank: None")
  401.         return
  402.     elif points > 0 and points < 5:
  403.         rank = 'Bronze'
  404.     elif points >= 5 and points < 15:
  405.         rank = 'Silver'
  406.     elif points >= 15 and points < 35:
  407.         rank = 'Gold'
  408.     elif points >= 35 and points < 60:
  409.         rank = 'Platinum'
  410.     elif points >= 60:
  411.         rank = 'Diamond'
  412.     role2 = discord.utils.get(ctx.guild.roles, name = rank)
  413.     await member.add_roles(role2)
  414.     await member.send(f"Current score: {points}\nCurrent rank: {rank}")
  415.  
  416.  
  417. #help command
  418. @client.command()
  419. @commands.has_role('Staff')
  420. async def help(ctx):
  421.     await ctx.send ("Here is a list of my commands: \n**kick** - to kick members the server, they can return if they have a link. \n**ban**- To ban members so they cannot return to the server.\n**clear** - to clear chats. \n**warn** - Warns a user. \n**mute** - Adds the Jester role to a user and removes the member role. \n**unmute** - Removes the jester role and adds the member role.")
  422.  
  423.  
  424. @client.command()
  425. async def hitbox(ctx, name: str, move: str):
  426.     labels = ["Base Knockback", "Angle", "Damage", "Knockback Growth", "Frame", "FAF", "Self Damage"]
  427.     try:
  428.         data = config.hitboxData[name][move]
  429.     except KeyError:
  430.         await ctx.send("Invalid character or move name")
  431.         return
  432.  
  433.     embed = discord.Embed(color=0x7289da)
  434.     for i in range(7):
  435.         embed.add_field(name=labels[i], value=data[i])
  436.     embed.set_footer(text="Hitbox made by " + data[7])
  437.     embed.set_image(url=data[8])
  438.     await ctx.send(embed=embed)
  439.  
  440.  
  441. #meme commands
  442. @client.command()
  443. async def reminder(ctx, num: (float or int), t_f, *, reminder):
  444.     if t_f == "h":
  445.         await ctx.send('reminder has been set!')
  446.         time = (num * 3600)
  447.         await asyncio.sleep(time)
  448.         author = ctx.message.author
  449.         await ctx.send(f'{author.mention}: {reminder}')
  450.     elif t_f == "s":
  451.         await ctx.send('reminder has been set!')
  452.         time = num
  453.         await asyncio.sleep(time)
  454.         author = ctx.message.author
  455.         await ctx.send(f'{author.mention}: {reminder}')
  456.     elif t_f == "m":
  457.         await ctx.send('reminder has been set!')
  458.         time = (num * 60)
  459.         await asyncio.sleep(time)
  460.         author = ctx.message.author
  461.         await ctx.send(f'{author.mention}: {reminder}')
  462.  
  463.  
  464. @client.command()
  465. async def leaderboard(ctx):
  466.     board = collection.find({ }).limit(10).sort('points', pymongo.DESCENDING)
  467.     msg = ""
  468.     for idx, player in enumerate(board, start=1):
  469.         msg += f'#{idx}  Name: {player.get("name")}  Points: {player.get("points")}\n'
  470.     await ctx.send(msg)
  471.  
  472.  
  473. client.run(config.TOKEN)