-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.py
130 lines (101 loc) · 4.44 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import discord
from discord.ext import commands
import random
import json
from datetime import datetime
import pytz
client = commands.Bot(command_prefix="!")
local_tz = timezone('Asia/Dubai')
nowtime = datetime.now(local_tz)
class Slapper(commands.Converter):
async def convert(self, ctx, argument):
to_slap = random.choice(ctx.guild.members)
return '{0.author} slapped {1} because *{2}*'.format(ctx, to_slap, argument)
@client.event
async def on_ready():
print("Bot is ready")
@client.command()
async def slap(ctx, *, reason: Slapper):
await ctx.send(reason)
@client.command()
async def slaphard(ctx, members: commands.Greedy[discord.Member], *, reason='no reason'):
slapped = " and ".join(x.name for x in members)
await ctx.send('{} just got slapped for {}'.format(slapped, reason))
@client.command()
async def joined(ctx, *, member: discord.Member):
await ctx.send('{0} joined on {0.joined_at}'.format(member))
@client.command()
async def hello(ctx):
await ctx.send("Hi there, " + str(ctx.author) + " of the " + str(ctx.guild) + ".")
@client.command()
async def greet(ctx, timezone):
cur_tz = timezone(timezone)
current_time = cur_tz.localize(nowtime)
@client.command()
async def info(ctx):
embed = discord.Embed(
title = "Introduction to Slither and its commands",
descriptiion = "Slither is a bot made by @wakandawarrior to spice up and try to aid all of those involved in this server. If you have any ideas as to how I may be improved, please talk to him",
colour = discord.Colour(int("0dfaab", 16))
)
embed.set_footer(text="Created by an absolute novice")
embed.set_image(url='https://cdn.discordapp.com/avatars/684973286438076437/11d7951e4e89d4b97b7f93b641770917.png')
embed.set_thumbnail(url='https://cdn.discordapp.com/avatars/750429563028242512/2642f6de2a014e54f1ef29ccdfa9a1a3.png')
embed.set_author(name='Nana', icon_url='https://cdn.discordapp.com/avatars/684973286438076437/11d7951e4e89d4b97b7f93b641770917.png')
embed.add_field(name='!slaphard',value='Use slaphard to intentionally target a person or more with the wrath of your hand. For example, !slaphard @crocodilefag @wakandawarrior someone must face my wrath', inline=False)
embed.add_field(name='!slap', value='!slap is used to randomly targeta single person.A reason why also needs to be included. For example, !slap you stole my virignity', inline=False)
await ctx.send(embed=embed)
@client.command()
async def add_roles(ctx, rolename):
member = ctx.message.author
role = discord.utils.get(member.guild.roles, name=rolename)
await discord.Member.add_roles(member, role)
@client.event
async def on_member_join(member):
with open('users.json', 'r') as f:
users = json.load(f)
await update_data(users, member)
with open('users.json', 'w') as f:
json.dump(users, f)
@client.event
async def on_message(message):
if message.author.bot == False:
with open('users.json', 'r') as f:
users = json.load(f)
await update_data(users, message.author)
await add_experience(users, message.author, 5)
await level_up(users, message.author, message)
with open('users.json', 'w') as f:
json.dump(users, f)
await client.process_commands(message)
async def update_data(users, user):
if not f'{user.id}' in users:
users[f'{user.id}'] = {}
users[f'{user.id}']['experience'] = 0
users[f'{user.id}']['level'] = 1
async def add_experience(users, user, exp):
users[f'{user.id}']['experience'] += exp
async def level_up(users, user, message):
with open('levels.json', 'r') as g:
levels = json.load(g)
experience = users[f'{user.id}']['experience']
lvl_start = users[f'{user.id}']['level']
lvl_end = int(experience ** (1 / 4))
if lvl_start < lvl_end:
await message.channel.send(f'{user.mention} has leveled up to level {lvl_end}')
users[f'{user.id}']['level'] = lvl_end
@client.command()
async def level(ctx, member: discord.Member = None):
if not member:
id = ctx.message.author.id
with open('users.json', 'r') as f:
users = json.load(f)
lvl = users[str(id)]['level']
await ctx.send(f'You are at level {lvl}!')
else:
id = member.id
with open('users.json', 'r') as f:
users = json.load(f)
lvl = users[str(id)]['level']
await ctx.send(f'{member} is at level {lvl}!')
client.run(token)