import discord
from discord.ext import commands
import asyncio
import random
import time
import config
import pymongo
from pymongo import MongoClient, ReturnDocument
cluster = MongoClient(config.MONGOURI)
db = cluster['crymebot']
collection = db['matchmaking']
client = commands.Bot(command_prefix = config.PREFIX, help_command=None)
@client.event
async def on_ready():
print("Bot is online!")
game = discord.Game("*arenahelp")
await client.change_presence(activity=game)
#start of moderation code
@client.command()
@commands.has_role("Staff")
async def mute(ctx, member: discord.Member, *, Reason = None):
channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
role = discord.utils.get(ctx.guild.roles, name = "Jester")
role2 = discord.utils.get(ctx.guild.roles, name = "Member")
role3 = discord.utils.get(ctx.guild.roles, name = "日本人")
role4 = discord.utils.get(ctx.guild.roles, name = "Europe")
user = ctx.message.author
await member.add_roles(role)
await member.remove_roles(role2)
await member.remove_roles(role3)
await channel.send(f'{member} has been muted.\nReason: {Reason}')
await member.send(f'You have been muted by {user}\nReason: {Reason}')
@client.command()
@commands.has_role("Staff")
async def unmute(ctx, member: discord.Member, *, Reason = None):
channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
role = discord.utils.get(ctx.guild.roles, name = "Jester")
role2 = discord.utils.get(ctx.guild.roles, name = "Member")
user = ctx.message.author
await member.add_roles(role2)
await member.remove_roles(role)
await channel.send(f'{member} has been unmuted by {user}.\nReason: {Reason}')
await member.send(f'You have been unmuted please do not repeat the same offense')
@client.command()
@commands.has_role("Staff")
async def warn(ctx, member: discord.Member, *,reason=None):
channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
staff= ctx.message.author
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.")
await channel.send(f'{member} has been issued a warning. \nReason: {reason}')
@client.command()
@commands.has_role("Staff")
async def send(ctx, member: discord.Member, *, message=None):
await member.send(f'{message}')
@client.command()
@commands.has_role('Staff')
async def kick(ctx, member: discord.Member, *, reason = "No reason has been given"):
channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
await member.kick(reason=reason)
await channel.send(f'{member} has been kicked from the server.\nReason: {reason}.')
await member.send(f'You have been kicked.\n{reason}')
@client.command()
@commands.has_role('Staff')
async def ban(ctx, userId: int, *, reason= "No reason has been provided"):
channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
author = ctx.message.author
user = discord.Object(userId)
try:
await ctx.guild.ban(user)
except discord.errors.NotFound:
await ctx.channel.send(f'{userId} not found')
return
await channel.send(f'{user} has been banned by {author}.\nReason: {reason}')
@client.command()
@commands.has_role('Staff')
async def clear(ctx, amount=1):
await ctx.channel.purge(limit=amount + 1 )
#start of matchmaking commmands
@client.command()
async def arenahelp(ctx):
author = ctx.message.author
await author.send("***arena <ArenaID> <Password> <opponent>**")
@client.command()
async def arena(ctx, ID, PASS, member: discord.Member):
author = ctx.message.author
guild = ctx.message.guild
roll1 = random.randint(1,6)
roll2 = random.randint(1,6)
name = 'Matchmaking'
category = discord.utils.get(ctx.guild.categories, name=name)
channel = await guild.create_text_channel(f'{author.id}', category = category)
embed = discord.Embed(
title = f'{author} arena',
)
embed.set_image( url = "https://cdn.discordapp.com/attachments/647064695487856643/647064925679779840/Jjj8iy7.png")
embed.add_field(name = "**ArenaID**", value = (ID), inline = False)
embed.add_field(name = "**Password**", value = (PASS), inline = True)
embed.set_thumbnail(url = "https://cdn.discordapp.com/attachments/597260087588814848/647107613846405120/Logo_SnR_simple_.png")
embed.set_footer(text= "Legal maps and stages")
await channel.send(f'{member.mention} vs {author.mention}')
await channel.send(embed=embed)
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)`")
await channel.send("Once you are done the creator of the arena must use *close @<nameofwinner> @<nameofloser> Score")
if roll1 > roll2:
await channel.send(f'**{member} has rolled higher and shall ban first**')
if roll1 < roll2:
await channel.send(f'**{author} has rolled higher and shall ban first **')
@client.command()
async def close(ctx, winner: discord.Member, loser: discord.Member, *, score):
channel = discord.utils.get(ctx.guild.text_channels, name = f'{ctx.message.author.id}')
await channel.delete()
embed = discord.Embed(title = f'{winner} vs {loser}')
embed.set_thumbnail(url = "https://cdn.discordapp.com/attachments/597260087588814848/647107613846405120/Logo_SnR_simple_.png")
embed.add_field(name = 'Final score', value = f'{score}')
embed.add_field(name = 'Winner', value = f'{winner}')
channel = discord.utils.get(ctx.guild.text_channels, name = 'ladder-results')
await channel.send(embed=embed)
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']
await addRank(ctx, winner, winnersPoints)
oldPoints = collection.find_one({ '_id': loser.id })
if oldPoints is None:
losersPoints = 0
collection.insert_one({ '_id': loser.id, 'name': f'{loser.name}#{loser.discriminator}', 'points': 0 })
elif oldPoints['points'] <= 0:
losersPoints = 0
else:
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']
await addRank(ctx, loser, losersPoints)
async def addRank(ctx, member: discord.Member, points):
roles = ['Bronze', 'Silver', 'Gold', 'Platinum', 'Diamond']
for x in roles:
role = discord.utils.get(ctx.guild.roles, name = x)
await member.remove_roles(role)
if points == 0:
await member.send(f"Current score: 0\nCurrent rank: None")
return
elif points > 0 and points < 5:
rank = 'Bronze'
elif points >= 5 and points < 15:
rank = 'Silver'
elif points >= 15 and points < 35:
rank = 'Gold'
elif points >= 35 and points < 60:
rank = 'Platinum'
elif points >= 60:
rank = 'Diamond'
role2 = discord.utils.get(ctx.guild.roles, name = rank)
await member.add_roles(role2)
await member.send(f"Current score: {points}\nCurrent rank: {rank}")
#help command
@client.command()
@commands.has_role('Staff')
async def help(ctx):
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.")
@client.command()
async def hitbox(ctx, name: str, move: str):
labels = ["Base Knockback", "Angle", "Damage", "Knockback Growth", "Frame", "FAF", "Self Damage"]
try:
data = config.hitboxData[name][move]
except KeyError:
await ctx.send("Invalid character or move name")
return
embed = discord.Embed(color=0x7289da)
for i in range(7):
embed.add_field(name=labels[i], value=data[i])
embed.set_footer(text="Hitbox made by " + data[7])
embed.set_image(url=data[8])
await ctx.send(embed=embed)
#meme commands
@client.command()
async def reminder(ctx, num: (float or int), t_f, *, reminder):
if t_f == "h":
await ctx.send('reminder has been set!')
time = (num * 3600)
await asyncio.sleep(time)
author = ctx.message.author
await ctx.send(f'{author.mention}: {reminder}')
elif t_f == "s":
await ctx.send('reminder has been set!')
time = num
await asyncio.sleep(time)
author = ctx.message.author
await ctx.send(f'{author.mention}: {reminder}')
elif t_f == "m":
await ctx.send('reminder has been set!')
time = (num * 60)
await asyncio.sleep(time)
author = ctx.message.author
await ctx.send(f'{author.mention}: {reminder}')
@client.command()
async def leaderboard(ctx):
board = collection.find({ }).limit(10).sort('points', pymongo.DESCENDING)
msg = ""
for idx, player in enumerate(board, start=1):
msg += f'#{idx} Name: {player.get("name")} Points: {player.get("points")}\n'
await ctx.send(msg)
client.run(config.TOKEN)import discord
from discord.ext import commands
import asyncio
import random
import time
import config
import pymongo
from pymongo import MongoClient, ReturnDocument
cluster = MongoClient(config.MONGOURI)
db = cluster['crymebot']
collection = db['matchmaking']
client = commands.Bot(command_prefix = config.PREFIX, help_command=None)
@client.event
async def on_ready():
print("Bot is online!")
game = discord.Game("*arenahelp")
await client.change_presence(activity=game)
#start of moderation code
@client.command()
@commands.has_role("Staff")
async def mute(ctx, member: discord.Member, *, Reason = None):
channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
role = discord.utils.get(ctx.guild.roles, name = "Jester")
role2 = discord.utils.get(ctx.guild.roles, name = "Member")
role3 = discord.utils.get(ctx.guild.roles, name = "日本人")
role4 = discord.utils.get(ctx.guild.roles, name = "Europe")
user = ctx.message.author
await member.add_roles(role)
await member.remove_roles(role2)
await member.remove_roles(role3)
await channel.send(f'{member} has been muted.\nReason: {Reason}')
await member.send(f'You have been muted by {user}\nReason: {Reason}')
@client.command()
@commands.has_role("Staff")
async def unmute(ctx, member: discord.Member, *, Reason = None):
channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
role = discord.utils.get(ctx.guild.roles, name = "Jester")
role2 = discord.utils.get(ctx.guild.roles, name = "Member")
user = ctx.message.author
await member.add_roles(role2)
await member.remove_roles(role)
await channel.send(f'{member} has been unmuted by {user}.\nReason: {Reason}')
await member.send(f'You have been unmuted please do not repeat the same offense')
@client.command()
@commands.has_role("Staff")
async def warn(ctx, member: discord.Member, *,reason=None):
channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
staff= ctx.message.author
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.")
await channel.send(f'{member} has been issued a warning. \nReason: {reason}')
@client.command()
@commands.has_role("Staff")
async def send(ctx, member: discord.Member, *, message=None):
await member.send(f'{message}')
@client.command()
@commands.has_role('Staff')
async def kick(ctx, member: discord.Member, *, reason = "No reason has been given"):
channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
await member.kick(reason=reason)
await channel.send(f'{member} has been kicked from the server.\nReason: {reason}.')
await member.send(f'You have been kicked.\n{reason}')
@client.command()
@commands.has_role('Staff')
async def ban(ctx, userId: int, *, reason= "No reason has been provided"):
channel = discord.utils.get(ctx.guild.text_channels, name="punishment_log")
author = ctx.message.author
user = discord.Object(userId)
try:
await ctx.guild.ban(user)
except discord.errors.NotFound:
await ctx.channel.send(f'{userId} not found')
return
await channel.send(f'{user} has been banned by {author}.\nReason: {reason}')
@client.command()
@commands.has_role('Staff')
async def clear(ctx, amount=1):
await ctx.channel.purge(limit=amount + 1 )
#start of matchmaking commmands
@client.command()
async def arenahelp(ctx):
author = ctx.message.author
await author.send("***arena <ArenaID> <Password> <opponent>**")
@client.command()
async def arena(ctx, ID, PASS, member: discord.Member):
author = ctx.message.author
guild = ctx.message.guild
roll1 = random.randint(1,6)
roll2 = random.randint(1,6)
name = 'Matchmaking'
category = discord.utils.get(ctx.guild.categories, name=name)
channel = await guild.create_text_channel(f'{author.id}', category = category)
embed = discord.Embed(
title = f'{author} arena',
)
embed.set_image( url = "https://cdn.discordapp.com/attachments/647064695487856643/647064925679779840/Jjj8iy7.png")
embed.add_field(name = "**ArenaID**", value = (ID), inline = False)
embed.add_field(name = "**Password**", value = (PASS), inline = True)
embed.set_thumbnail(url = "https://cdn.discordapp.com/attachments/597260087588814848/647107613846405120/Logo_SnR_simple_.png")
embed.set_footer(text= "Legal maps and stages")
await channel.send(f'{member.mention} vs {author.mention}')
await channel.send(embed=embed)
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)`")
await channel.send("Once you are done the creator of the arena must use *close @<nameofwinner> @<nameofloser> Score")
if roll1 > roll2:
await channel.send(f'**{member} has rolled higher and shall ban first**')
if roll1 < roll2:
await channel.send(f'**{author} has rolled higher and shall ban first **')
@client.command()
async def close(ctx, winner: discord.Member, loser: discord.Member, *, score):
channel = discord.utils.get(ctx.guild.text_channels, name = f'{ctx.message.author.id}')
await channel.delete()
embed = discord.Embed(title = f'{winner} vs {loser}')
embed.set_thumbnail(url = "https://cdn.discordapp.com/attachments/597260087588814848/647107613846405120/Logo_SnR_simple_.png")
embed.add_field(name = 'Final score', value = f'{score}')
embed.add_field(name = 'Winner', value = f'{winner}')
channel = discord.utils.get(ctx.guild.text_channels, name = 'ladder-results')
await channel.send(embed=embed)
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']
await addRank(ctx, winner, winnersPoints)
oldPoints = collection.find_one({ '_id': loser.id })
if oldPoints is None:
losersPoints = 0
collection.insert_one({ '_id': loser.id, 'name': f'{loser.name}#{loser.discriminator}', 'points': 0 })
elif oldPoints['points'] <= 0:
losersPoints = 0
else:
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']
await addRank(ctx, loser, losersPoints)
async def addRank(ctx, member: discord.Member, points):
roles = ['Bronze', 'Silver', 'Gold', 'Platinum', 'Diamond']
for x in roles:
role = discord.utils.get(ctx.guild.roles, name = x)
await member.remove_roles(role)
if points == 0:
await member.send(f"Current score: 0\nCurrent rank: None")
return
elif points > 0 and points < 5:
rank = 'Bronze'
elif points >= 5 and points < 15:
rank = 'Silver'
elif points >= 15 and points < 35:
rank = 'Gold'
elif points >= 35 and points < 60:
rank = 'Platinum'
elif points >= 60:
rank = 'Diamond'
role2 = discord.utils.get(ctx.guild.roles, name = rank)
await member.add_roles(role2)
await member.send(f"Current score: {points}\nCurrent rank: {rank}")
#help command
@client.command()
@commands.has_role('Staff')
async def help(ctx):
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.")
@client.command()
async def hitbox(ctx, name: str, move: str):
labels = ["Base Knockback", "Angle", "Damage", "Knockback Growth", "Frame", "FAF", "Self Damage"]
try:
data = config.hitboxData[name][move]
except KeyError:
await ctx.send("Invalid character or move name")
return
embed = discord.Embed(color=0x7289da)
for i in range(7):
embed.add_field(name=labels[i], value=data[i])
embed.set_footer(text="Hitbox made by " + data[7])
embed.set_image(url=data[8])
await ctx.send(embed=embed)
#meme commands
@client.command()
async def reminder(ctx, num: (float or int), t_f, *, reminder):
if t_f == "h":
await ctx.send('reminder has been set!')
time = (num * 3600)
await asyncio.sleep(time)
author = ctx.message.author
await ctx.send(f'{author.mention}: {reminder}')
elif t_f == "s":
await ctx.send('reminder has been set!')
time = num
await asyncio.sleep(time)
author = ctx.message.author
await ctx.send(f'{author.mention}: {reminder}')
elif t_f == "m":
await ctx.send('reminder has been set!')
time = (num * 60)
await asyncio.sleep(time)
author = ctx.message.author
await ctx.send(f'{author.mention}: {reminder}')
@client.command()
async def leaderboard(ctx):
board = collection.find({ }).limit(10).sort('points', pymongo.DESCENDING)
msg = ""
for idx, player in enumerate(board, start=1):
msg += f'#{idx} Name: {player.get("name")} Points: {player.get("points")}\n'
await ctx.send(msg)
client.run(config.TOKEN)