-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
285 lines (247 loc) · 8.64 KB
/
Copy pathbot.py
File metadata and controls
285 lines (247 loc) · 8.64 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
from discord.ext import commands, tasks
import json
import discord
import asyncio
from meme import meme
import os
import time
import functools
import schedule
import datetime
from foodlist import generate_jsonfile
with open("./configs/discord_conf.json") as discord_conf:
token = json.load(discord_conf)["token"]
bot = commands.Bot(command_prefix=",")
@commands.cooldown(1.0, 60.0)
@bot.command()
@commands.is_owner()
async def json_generate(ctx):
await ctx.channel.send("generating json")
h = generate_jsonfile()
if h == "success":
await ctx.channel.send("json generated")
elif h == "error":
await ctx.channel.send("there was a error while making the json file")
@bot.command()
@commands.is_owner()
async def todo(ctx, arg, title="all", *args):
if arg == "add":
data = ""
json_data = {}
for s in args:
data += s
data += " "
data = data[:-1]
json_data.update({title:data})
embed=discord.Embed(title="Added TODO", color=0x4d4d4d)
embed.add_field(name=title, value=data, inline=False)
with open("./data/todo.json", "r+", encoding='utf8') as f:
data = json.load(f)
data.update(json_data)
f.seek(0)
json.dump(data, f, ensure_ascii=False)
await ctx.send(embed=embed)
elif arg == "list":
if title == "all":
with open("./data/todo.json", encoding='utf-8') as s:
data = json.load(s)
embed=discord.Embed(title="TODO List", color=0x4d4d4d)
if data == {}:
embed.add_field(name="TODO List is empty", value="Use ,todo add (title) (note)", inline=False)
for x in data:
embed.add_field(name=x, value=data[x], inline=False)
await ctx.send(embed=embed)
else:
"""
embed=discord.Embed(title="TODO List", color=0x4d4d4d)
with open("./data/todo.json", encoding="utf8" ) as h:
data = json.load(h)
for x in data:
embed.add_field(name=x, value=data[x], inline=False)
"""
elif arg == "del":
with open("./data/todo.json", encoding='utf-8') as s:
data = json.load(s)
try:
h1 = data[title]
data.pop(title)
with open("./data/todo.json", 'w', encoding='utf8') as f:
json.dump(data, f, ensure_ascii=False)
embed=discord.Embed(title="Deleted todo " + title , color=0xFF5733)
embed.add_field(name=title, value=h1, inline=False)
except:
embed=discord.Embed(title="There is no " + title, color=0xFF5733)
await ctx.send(embed=embed)
else:
await ctx.channel.send("unknown arg")
@bot.command(aliases=["r","meme"])
@commands.is_owner()
async def reddit(ctx, command):
is_logged_aliases = ["islogged","is_logged","is_logged_in"]
if command in is_logged_aliases:
print(meme.is_logged)
await ctx.channel.send(meme.is_logged())
else:
await ctx.channel.send("unknow command")
@bot.command(aliases=["fl","sapuska"])
async def foodlist(ctx, *args):
skip=False
if time.time() - os.stat("./data/foods.json").st_mtime > 3000:
h = await bot.loop.run_in_executor(None, functools.partial(generate_jsonfile))
if h == "error":
await ctx.channel.send("there was a error while making the json file")
skip = True
sapuska = ""
if args == ():
sapuska = "Viikon sapuskat"
args = ["ma","ti","ke","to","pe"]
date = ""
dates = []
ma_args = ["manantai","ma","mon","monday"]
ti_args = ["tiistai","ti","tue","tues","tuesday"]
ke_args = ["keskiviikko","ke","wed","weds","wednesday"]
to_args = ["torstai","to","thu","thur","thurs","thursday"]
pe_args = ["perjantai","pe","fri","friday"]
help_args = ["help","apua","h","?"]
for input_arg in args:
date = input_arg.lower()
if date in ma_args:
if not "ma" in dates:
dates.append("ma")
elif date in ti_args:
if not "ti" in dates:
dates.append("ti")
elif date in ke_args:
if not "ke" in dates:
dates.append("ke")
elif date in to_args:
if not "to" in dates:
dates.append("to")
elif date in pe_args:
if not "pe" in dates:
dates.append("pe")
elif date in help_args:
if not "help" in dates:
dates.append("help")
args = dates
if args == []:
embed=discord.Embed(title="",description="invalid argument where given\nsee ,foodlist help for help", color=0xFF5733)
await ctx.send(embed=embed)
skip = True
if "help" in args:
des = """
",foodlist help" to show this
",foodlist" to show all days
",foodlist specific day" to show a specific day
valid days are ma ti ke to pe
"""
embed=discord.Embed(title="food list",description=des, color=0x4d4d4d)
await ctx.send(embed=embed)
skip = True
if not skip:
with open("./data/foods.json", encoding='utf-8') as s:
foodlist = json.load(s)
if not sapuska == "Viikon sapuskat":
sapuska = "Sapuskat"
if len(args) == 1:
sapuska = "Tänä päivän Sapuskaa"
embed=discord.Embed(title=sapuska, color=0x4d4d4d)
args2 = ["ma","ti","ke","to","pe"]
for x in args2:
if x in args:
k = foodlist[x]
foods = "\n"
foods = foods.join(k[1:])
embed.add_field(name=k[0], value=foods, inline=False)
await ctx.send(embed=embed)
"""
@tasks.loop(seconds=5.0)
async def sch(ctx):
schedule.run_pending()
@bot.command()
async def dayly(ctx):
date = ""
dates = []
ma_args = ["manantai","ma","mon","monday"]
ti_args = ["tiistai","ti","tue","tues","tuesday"]
ke_args = ["keskiviikko","ke","wed","weds","wednesday"]
to_args = ["torstai","to","thu","thur","thurs","thursday"]
pe_args = ["perjantai","pe","fri","friday"]
help_args = ["help","apua","h","?"]
#date = datetime.date.today().strftime("%A").lower()
date = "monday"
print(date)
if date in ma_args:
if not "ma" in dates:
dates.append("ma")
elif date in ti_args:
if not "ti" in dates:
dates.append("ti")
elif date in ke_args:
if not "ke" in dates:
dates.append("ke")
elif date in to_args:
if not "to" in dates:
dates.append("to")
elif date in pe_args:
if not "pe" in dates:
dates.append("pe")
print(dates)
if dates == []:
print("brick")
pass
else:
print("jee")
with open("./data/foods.json", encoding='utf-8') as s:
foodlist = json.load(s)
sapuska = "Tänäpäivän ruoka on"
embed=discord.Embed(title=sapuska, description="@FL-listener ", color=0x4d4d4d)
args2 = ["ma","ti","ke","to","pe"]
for x in args2:
if x in dates:
k = foodlist[x]
foods = "\n"
foods = foods.join(k[1:])
embed.add_field(name=k[0], value=foods, inline=False)
await ctx.send(embed=embed)
"""
@bot.command()
@commands.is_owner()
async def cat(ctx, arg):
nono_files = ["./configs/discord_conf.json"]
if arg in nono_files:
await ctx.channel.send("you cant open that. thats a nono file")
else:
try:
k = open(arg, encoding='utf-8')
h = k.read()
k.close()
style = ""
if arg.endswith(".py"):
style = "py"
if arg.endswith(".json"):
style = "json"
await ctx.channel.send("```" + style + "\n" + h + "```")
except Exception as e:
await ctx.channel.send("Error:" + e)
@bot.command()
@commands.is_owner()
async def restart(ctx):
await ctx.channel.send("Restarting")
await ctx.bot.logout()
@bot.command()
@commands.is_owner()
async def shutdown(ctx):
await ctx.channel.send("Shuttingdown")
await ctx.bot.logout()
"""
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.send(f"Command on cooldown, try again in: {round(error.retry_after)} seconds.")
if isinstance(error, commands.NotOwner):
await ctx.send(f"you aint the bot owener")
"""
#schedule.every().day.at("10:30").do(dayly)
print("Logged in Titityy")
bot.run(token)