Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -98,8 +98,8 @@ def ec(x, fd="<|image|>", sd="<|image|>"):
|
|
98 |
|
99 |
intents = discord.Intents.default()
|
100 |
intents.message_content = True
|
101 |
-
|
102 |
client = discord.Client(intents=intents)
|
|
|
103 |
|
104 |
@client.event
|
105 |
async def on_ready():
|
@@ -109,6 +109,7 @@ async def on_ready():
|
|
109 |
else:
|
110 |
print(f"Logged in as {client.user}")
|
111 |
presence.start()
|
|
|
112 |
|
113 |
|
114 |
@client.event
|
@@ -203,6 +204,70 @@ bannedUsers = json.loads(info)["bannedUsers"]
|
|
203 |
imageModel = json.loads(info)["imageModel"]
|
204 |
userTimes = json.loads(info)["userTimes"]
|
205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
@client.event
|
207 |
async def on_message(message):
|
208 |
msgchannel = message.channel
|
@@ -222,88 +287,6 @@ async def on_message(message):
|
|
222 |
|
223 |
with open(f"{guild_name}.guild", "a") as f:
|
224 |
f.write("")
|
225 |
-
if message.content.startswith("--setup"):
|
226 |
-
args = message.content.split()
|
227 |
-
del args[0]
|
228 |
-
if len(args) == 0:
|
229 |
-
with open(f"{guild_name}.guild", "a") as f:
|
230 |
-
f.write(f"{msgchannel.id}\n")
|
231 |
-
embed = discord.Embed(title="Success!", description=f"You can now chat with the bot in <#{msgchannel.id}>")
|
232 |
-
await message.reply(embed=embed)
|
233 |
-
return 0
|
234 |
-
if args[0] == "":
|
235 |
-
embed = discord.Embed(title="Error", description="Parameter `[channel]` empty. Use `--help` for command help.")
|
236 |
-
await message.reply(embed=embed)
|
237 |
-
return 0
|
238 |
-
if args[0].startswith("<#") and args[0].endswith(">"):
|
239 |
-
try:
|
240 |
-
cid = int(args[0][2:-1])
|
241 |
-
except:
|
242 |
-
embed = discord.Embed(title="Error", description="Parameter `[channel]` invalid. Use `--help` for command help.")
|
243 |
-
await message.reply(embed=embed)
|
244 |
-
return 0
|
245 |
-
c = client.get_channel(cid)
|
246 |
-
if c in message.guild.text_channels:
|
247 |
-
with open(f"{guild_name}.guild", "a") as f:
|
248 |
-
f.write(f"{c.id}\n")
|
249 |
-
embed = discord.Embed(title="Success!", description=f"You can now chat with the bot in <#{cid}>")
|
250 |
-
await message.reply(embed=embed)
|
251 |
-
return 0
|
252 |
-
else:
|
253 |
-
embed = discord.Embed(title="Error", description="Parameter `[channel]` is not in this guild. Use `--help` for command help.")
|
254 |
-
await message.reply(embed=embed)
|
255 |
-
return 0
|
256 |
-
else:
|
257 |
-
embed = discord.Embed(title="Error", description="Parameter `[channel]` is not in valid forms. Use `--help` for command help.")
|
258 |
-
await message.reply(embed=embed)
|
259 |
-
return 0
|
260 |
-
|
261 |
-
if message.content.startswith("--revoke"):
|
262 |
-
args = message.content.split()
|
263 |
-
del args[0]
|
264 |
-
if len(args) == 0:
|
265 |
-
with open(f"{guild_name}.guild", "r") as f:
|
266 |
-
k = f.read().split("\n")
|
267 |
-
cid = message.channel.id
|
268 |
-
if str(cid) in k:
|
269 |
-
k.remove(str(cid))
|
270 |
-
with open(f"{guild_name}.guild", "w") as f:
|
271 |
-
f.write("\n".join(k))
|
272 |
-
embed = discord.Embed(title="Success", description=f"Lyre is now unable to chat in <#{msgchannel.id}>")
|
273 |
-
await message.reply(embed=embed)
|
274 |
-
return 0
|
275 |
-
else:
|
276 |
-
embed = discord.Embed(title="Error", description=f"Lyre was already unable to chat in <#{msgchannel.id}>")
|
277 |
-
await message.reply(embed=embed)
|
278 |
-
return 0
|
279 |
-
if args[0] == "":
|
280 |
-
embed = discord.Embed(title="Error", description="Parameter `[channel]` empty. Use `--help` for command help.")
|
281 |
-
await message.reply(embed=embed)
|
282 |
-
return 0
|
283 |
-
if args[0].startswith("<#") and args[0].endswith(">"):
|
284 |
-
try:
|
285 |
-
cid = int(args[0][2:-1])
|
286 |
-
except:
|
287 |
-
embed = discord.Embed(title="Error", description="Parameter `[channel]` invalid. Use `--help` for command help.")
|
288 |
-
await message.reply(embed=embed)
|
289 |
-
return 0
|
290 |
-
with open(f"{guild_name}.guild", "r") as f:
|
291 |
-
k = f.read().split("\n")
|
292 |
-
if str(cid) in k:
|
293 |
-
k.remove(str(cid))
|
294 |
-
with open(f"{guild_name}.guild", "w") as f:
|
295 |
-
f.write("\n".join(k))
|
296 |
-
embed = discord.Embed(title="Success", description=f"Lyre is now unable to chat in {args[0]}")
|
297 |
-
await message.reply(embed=embed)
|
298 |
-
return 0
|
299 |
-
else:
|
300 |
-
embed = discord.Embed(title="Error", description=f"Lyre was already unable to chat in {args[0]}")
|
301 |
-
await message.reply(embed=embed)
|
302 |
-
return 0
|
303 |
-
else:
|
304 |
-
embed = discord.Embed(title="Error", description="Parameter `[channel]` is not in valid forms, or does not exist. Use `--help` for command help.")
|
305 |
-
await message.reply(embed=embed)
|
306 |
-
return 0
|
307 |
|
308 |
if message.content.startswith("--reset"):
|
309 |
args = message.content.split()
|
|
|
98 |
|
99 |
intents = discord.Intents.default()
|
100 |
intents.message_content = True
|
|
|
101 |
client = discord.Client(intents=intents)
|
102 |
+
tree = app_commands.CommandTree(client)
|
103 |
|
104 |
@client.event
|
105 |
async def on_ready():
|
|
|
109 |
else:
|
110 |
print(f"Logged in as {client.user}")
|
111 |
presence.start()
|
112 |
+
synced = await client.tree.sync()
|
113 |
|
114 |
|
115 |
@client.event
|
|
|
204 |
imageModel = json.loads(info)["imageModel"]
|
205 |
userTimes = json.loads(info)["userTimes"]
|
206 |
|
207 |
+
@client.tree.command()
|
208 |
+
@is_owner()
|
209 |
+
async def sync(ctx: Context) -> None:
|
210 |
+
synced = await client.tree.sync()
|
211 |
+
await ctx.reply("{} commands synced".format(len(synced)))
|
212 |
+
|
213 |
+
@client.tree.command(
|
214 |
+
description="Starts the conversation with Lyre.",
|
215 |
+
guild=discord.Object(id=1079318749116641320)
|
216 |
+
)
|
217 |
+
@app_commands.describe(
|
218 |
+
channel='The channel to start the conversation in. Defaults to the channel it was called in.',
|
219 |
+
)
|
220 |
+
@has_permissions(manage_channels=True, manage_messages=True)
|
221 |
+
async def start(ctx: discord.Interaction, channel: Optional[discord.AppCommandOptionType.channel]=None):
|
222 |
+
if channel == None:
|
223 |
+
chping = f"<#{ctx.channel_id}>"
|
224 |
+
with open(f"{guild_name}.guild", "a") as f:
|
225 |
+
f.write(f"{ctx.channel_id}\n")
|
226 |
+
else:
|
227 |
+
chping = f"<#{channel.id}>"
|
228 |
+
with open(f"{guild_name}.guild", "a") as f:
|
229 |
+
f.write(f"{channel.id}\n")
|
230 |
+
ctx.response.send_message(f"Started a conversation in {chping}")
|
231 |
+
|
232 |
+
@start.error
|
233 |
+
async def start_error(error, ctx):
|
234 |
+
if isinstance(error, commands.MissingPermissions):
|
235 |
+
ctx.response.send_message(f"Missing permissions in {chping}")
|
236 |
+
|
237 |
+
@client.tree.command(
|
238 |
+
description="Ends the conversation with Lyre.",
|
239 |
+
guild=discord.Object(id=1079318749116641320)
|
240 |
+
)
|
241 |
+
@app_commands.describe(
|
242 |
+
channel='The channel to end the conversation in. Defaults to the channel it was called in.',
|
243 |
+
)
|
244 |
+
@has_permissions(manage_channels=True, manage_messages=True)
|
245 |
+
async def end(ctx: discord.Interaction, channel: Optional[discord.AppCommandOptionType.channel]=None):
|
246 |
+
if channel == None:
|
247 |
+
chping = f"<#{ctx.channel_id}>"
|
248 |
+
with open(f"{guild_name}.guild", "r") as f:
|
249 |
+
k = f.read().split("\n")
|
250 |
+
cid = message.channel.id
|
251 |
+
if str(cid) in k:
|
252 |
+
k.remove(str(cid))
|
253 |
+
with open(f"{guild_name}.guild", "w") as f:
|
254 |
+
f.write("\n".join(k))
|
255 |
+
else:
|
256 |
+
await ctx.response.send_message(f"There was no conversation to end in {chping}")
|
257 |
+
return 0
|
258 |
+
else:
|
259 |
+
chping = f"<#{channel.id}>"
|
260 |
+
with open(f"{guild_name}.guild", "r") as f:
|
261 |
+
k = f.read().split("\n")channel.id
|
262 |
+
if str(cid) in k:
|
263 |
+
k.remove(str(cid))
|
264 |
+
with open(f"{guild_name}.guild", "w") as f:
|
265 |
+
f.write("\n".join(k))
|
266 |
+
else:
|
267 |
+
await ctx.response.send_message(f"There was no conversation to end in {chping}")
|
268 |
+
return 0
|
269 |
+
await ctx.response.send_message(f"Ended the conversation in {chping}")
|
270 |
+
|
271 |
@client.event
|
272 |
async def on_message(message):
|
273 |
msgchannel = message.channel
|
|
|
287 |
|
288 |
with open(f"{guild_name}.guild", "a") as f:
|
289 |
f.write("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
|
291 |
if message.content.startswith("--reset"):
|
292 |
args = message.content.split()
|