-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
129 lines (101 loc) · 3.92 KB
/
main.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
import os
import time
import json
import random
from discord.ext import commands
bot = commands.Bot(command_prefix="!")
def reverse(s):
str = ""
for i in s:
str = i + str
return str
def convert(seconds):
return time.strftime("%Hh %Mm %Ss", time.gmtime(seconds))
@bot.event
async def on_ready():
print(f"Signed in as {bot.user}")
@bot.command(aliases=['s'])
async def start(ctx):
with open('users.json', 'r') as f:
users = json.load(f)
users[str(ctx.author.id)] = {}
user_dict = users[str(ctx.author.id)]
user_dict['coins'] = 500
user_dict['job'] = {}
job = user_dict['job']
job['name'] = ''
job['salary'] = ''
user_dict['items'] = []
with open('users.json', 'w') as f:
json.dump(users, f, indent=4)
await ctx.send(':white_check_mark: **Success!** You are now entered!')
@bot.command(aliases=['bal', 'money', 'b'])
async def balance(ctx):
with open('users.json', 'r') as f:
users = json.load(f)
coins = users[str(ctx.author.id)]['coins']
await ctx.send(f"You have **{round(coins)}** coins, {ctx.author.mention}.")
@bot.command()
async def start_work(ctx, job):
with open('users.json', 'r') as f:
users = json.load(f)
with open('jobs.json', 'r') as f:
jobs = json.load(f)
jobs_dict = users[str(ctx.author.id)]['job']
if jobs_dict['name'] != '':
await ctx.send("You already have a job.")
return
else:
if job == 'YouTuber':
job_name = jobs['jobs'][0]['name']
salary = jobs['jobs'][0]['salary']
users[str(ctx.author.id)]['job']['name'] += job_name
users[str(ctx.author.id)]['job']['salary'] += str(salary)
with open('users.json', 'w') as f:
json.dump(users, f, indent=4)
await ctx.send(f"You are now working as a **{job_name}** and your salary is **{salary}**!")
else:
await ctx.send(':x: That job does not exist yet!')
return
@bot.command()
@commands.cooldown(1, 86400, commands.BucketType.user)
async def work_resign(ctx):
with open('users.json', 'r') as f:
users = json.load(f)
job = users[str(ctx.author.id)]['job']['name']
salary = users[str(ctx.author.id)]['job']['salary']
if job == '':
await ctx.send("You don't have a job. Do `!start_work YouTuber` to start your job.")
return
await ctx.send(f'You have resigned from your job as a **{job}** which had a salary of **{salary}**.')
users[str(ctx.author.id)]['job']['name'] = ''
users[str(ctx.author.id)]['job']['salary'] = ''
with open('users.json', 'w') as f:
json.dump(users, f, indent=4)
@bot.command()
@commands.cooldown(1, 3600, commands.BucketType.user)
async def work(ctx):
with open('users.json', 'r') as f:
users = json.load(f)
salary = users[str(ctx.author.id)]['job']['salary']
yt_words = open('yt_words.txt').read().split()
random_word = random.choice(yt_words)
print(reverse(random_word))
def check(m):
return m.author.id == ctx.author.id
await ctx.send(f'Enter the following word in reverse.\n`{random_word}`')
response = await bot.wait_for('message', check=check)
if response.content != reverse(random_word):
await ctx.send(f'You answered wrong, so you only get **{int(salary) / 2}** coins.')
users[str(ctx.author.id)]['coins'] += int(salary) / 2
else:
await ctx.send(f"Good job! You got it right. You get {salary} coins.")
users[str(ctx.author.id)]['coins'] += int(salary)
with open('users.json', 'w') as f:
json.dump(users, f, indent=4)
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
sec = round(error.retry_after)
await ctx.send(f"You are on cooldown. Try again in **{convert(sec)}**. ")
bot.run(os.environ.get("DISCORD_BOT_TOKEN"))