Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -15,10 +15,6 @@ import streamlit as st
|
|
15 |
from huggingface_hub import AsyncInferenceClient, login
|
16 |
import time
|
17 |
import os
|
18 |
-
from discord import app_commands
|
19 |
-
import requests
|
20 |
-
from discord.ext.commands import is_owner, Context, has_permissions
|
21 |
-
from typing import Optional
|
22 |
|
23 |
launch_time = datetime.datetime.utcnow()
|
24 |
|
@@ -102,8 +98,8 @@ def ec(x, fd="<|image|>", sd="<|image|>"):
|
|
102 |
|
103 |
intents = discord.Intents.default()
|
104 |
intents.message_content = True
|
|
|
105 |
client = discord.Client(intents=intents)
|
106 |
-
tree = app_commands.CommandTree(client)
|
107 |
|
108 |
@client.event
|
109 |
async def on_ready():
|
@@ -113,7 +109,6 @@ async def on_ready():
|
|
113 |
else:
|
114 |
print(f"Logged in as {client.user}")
|
115 |
presence.start()
|
116 |
-
synced = await client.tree.sync()
|
117 |
|
118 |
|
119 |
@client.event
|
@@ -203,75 +198,6 @@ or
|
|
203 |
--setup #general
|
204 |
```"""
|
205 |
|
206 |
-
info = requests.get("https://raw.githubusercontent.com/aryananumula/lr/main/info.json").content
|
207 |
-
bannedUsers = json.loads(info)["bannedUsers"]
|
208 |
-
imageModel = json.loads(info)["imageModel"]
|
209 |
-
userTimes = json.loads(info)["userTimes"]
|
210 |
-
|
211 |
-
@client.tree.command()
|
212 |
-
@is_owner()
|
213 |
-
async def sync(ctx: Context) -> None:
|
214 |
-
synced = await client.tree.sync()
|
215 |
-
await ctx.reply("{} commands synced".format(len(synced)))
|
216 |
-
|
217 |
-
@client.tree.command(
|
218 |
-
description="Starts the conversation with Lyre.",
|
219 |
-
guild=discord.Object(id=1079318749116641320)
|
220 |
-
)
|
221 |
-
@app_commands.describe(
|
222 |
-
channel='The channel to start the conversation in. Defaults to the channel it was called in.',
|
223 |
-
)
|
224 |
-
@has_permissions(manage_channels=True, manage_messages=True)
|
225 |
-
async def start(ctx: discord.Interaction, channel: Optional[discord.AppCommandOptionType.channel]=None):
|
226 |
-
if channel == None:
|
227 |
-
chping = f"<#{ctx.channel_id}>"
|
228 |
-
with open(f"{guild_name}.guild", "a") as f:
|
229 |
-
f.write(f"{ctx.channel_id}\n")
|
230 |
-
else:
|
231 |
-
chping = f"<#{channel.id}>"
|
232 |
-
with open(f"{guild_name}.guild", "a") as f:
|
233 |
-
f.write(f"{channel.id}\n")
|
234 |
-
ctx.response.send_message(f"Started a conversation in {chping}")
|
235 |
-
|
236 |
-
@start.error
|
237 |
-
async def start_error(error, ctx):
|
238 |
-
if isinstance(error, commands.MissingPermissions):
|
239 |
-
ctx.response.send_message(f"Missing permissions in {chping}")
|
240 |
-
|
241 |
-
@client.tree.command(
|
242 |
-
description="Ends the conversation with Lyre.",
|
243 |
-
guild=discord.Object(id=1079318749116641320)
|
244 |
-
)
|
245 |
-
@app_commands.describe(
|
246 |
-
channel='The channel to end the conversation in. Defaults to the channel it was called in.',
|
247 |
-
)
|
248 |
-
@has_permissions(manage_channels=True, manage_messages=True)
|
249 |
-
async def end(ctx: discord.Interaction, channel: Optional[discord.AppCommandOptionType.channel]=None):
|
250 |
-
if channel == None:
|
251 |
-
chping = f"<#{ctx.channel_id}>"
|
252 |
-
with open(f"{guild_name}.guild", "r") as f:
|
253 |
-
k = f.read().split("\n")
|
254 |
-
cid = message.channel.id
|
255 |
-
if str(cid) in k:
|
256 |
-
k.remove(str(cid))
|
257 |
-
with open(f"{guild_name}.guild", "w") as f:
|
258 |
-
f.write("\n".join(k))
|
259 |
-
else:
|
260 |
-
await ctx.response.send_message(f"There was no conversation to end in {chping}")
|
261 |
-
return 0
|
262 |
-
else:
|
263 |
-
chping = f"<#{channel.id}>"
|
264 |
-
with open(f"{guild_name}.guild", "r") as f:
|
265 |
-
k = f.read().split("\n")
|
266 |
-
if str(cid) in k:
|
267 |
-
k.remove(str(cid))
|
268 |
-
with open(f"{ctx.guild.name}.guild", "w") as f:
|
269 |
-
f.write("\n".join(k))
|
270 |
-
else:
|
271 |
-
await ctx.response.send_message(f"There was no conversation to end in {chping}")
|
272 |
-
return 0
|
273 |
-
await ctx.response.send_message(f"Ended the conversation in {chping}")
|
274 |
-
|
275 |
@client.event
|
276 |
async def on_message(message):
|
277 |
msgchannel = message.channel
|
@@ -291,6 +217,88 @@ async def on_message(message):
|
|
291 |
|
292 |
with open(f"{guild_name}.guild", "a") as f:
|
293 |
f.write("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
294 |
|
295 |
if message.content.startswith("--reset"):
|
296 |
args = message.content.split()
|
@@ -366,23 +374,10 @@ async def on_message(message):
|
|
366 |
message.content = message.content.replace(f"<@{user.id}>",
|
367 |
f"<@{str(user)}>")
|
368 |
try:
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
with open(f"usrtime/{message.author}", "w") as f:
|
374 |
-
f.write(str(round(time.time())))
|
375 |
-
er = 0
|
376 |
-
y = round(time.time()) - int(er)
|
377 |
-
print(y)
|
378 |
-
if str(message.author).lower() not in userTimes.keys():
|
379 |
-
usrTime = 5
|
380 |
-
else:
|
381 |
-
usrTime = userTimes[str(message.author).lower()]
|
382 |
-
if message.author.id in bannedUsers:
|
383 |
-
return 0
|
384 |
-
if y < usrTime:
|
385 |
-
return 0
|
386 |
s = f":green[{message.author}]: :violet[{message.content}] :blue[{msgchannel_name}] :orange[{guild_name}]"
|
387 |
if message.author == client.user:
|
388 |
return
|
@@ -461,6 +456,23 @@ async def on_message(message):
|
|
461 |
context = f.read()
|
462 |
with open(f"{guild_name}.guild", "r") as f:
|
463 |
o = f.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
464 |
if (str(message.channel.id) in o.split("\n")) or (guild_name == "Direct"):
|
465 |
with open(f"usrtime/{message.author}", "w") as f:
|
466 |
f.write(str(round(time.time())))
|
|
|
15 |
from huggingface_hub import AsyncInferenceClient, login
|
16 |
import time
|
17 |
import os
|
|
|
|
|
|
|
|
|
18 |
|
19 |
launch_time = datetime.datetime.utcnow()
|
20 |
|
|
|
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 |
else:
|
110 |
print(f"Logged in as {client.user}")
|
111 |
presence.start()
|
|
|
112 |
|
113 |
|
114 |
@client.event
|
|
|
198 |
--setup #general
|
199 |
```"""
|
200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
@client.event
|
202 |
async def on_message(message):
|
203 |
msgchannel = message.channel
|
|
|
217 |
|
218 |
with open(f"{guild_name}.guild", "a") as f:
|
219 |
f.write("")
|
220 |
+
if message.content.startswith("--setup"):
|
221 |
+
args = message.content.split()
|
222 |
+
del args[0]
|
223 |
+
if len(args) == 0:
|
224 |
+
with open(f"{guild_name}.guild", "a") as f:
|
225 |
+
f.write(f"{msgchannel.id}\n")
|
226 |
+
embed = discord.Embed(title="Success!", description=f"You can now chat with the bot in <#{msgchannel.id}>")
|
227 |
+
await message.reply(embed=embed)
|
228 |
+
return 0
|
229 |
+
if args[0] == "":
|
230 |
+
embed = discord.Embed(title="Error", description="Parameter `[channel]` empty. Use `--help` for command help.")
|
231 |
+
await message.reply(embed=embed)
|
232 |
+
return 0
|
233 |
+
if args[0].startswith("<#") and args[0].endswith(">"):
|
234 |
+
try:
|
235 |
+
cid = int(args[0][2:-1])
|
236 |
+
except:
|
237 |
+
embed = discord.Embed(title="Error", description="Parameter `[channel]` invalid. Use `--help` for command help.")
|
238 |
+
await message.reply(embed=embed)
|
239 |
+
return 0
|
240 |
+
c = client.get_channel(cid)
|
241 |
+
if c in message.guild.text_channels:
|
242 |
+
with open(f"{guild_name}.guild", "a") as f:
|
243 |
+
f.write(f"{c.id}\n")
|
244 |
+
embed = discord.Embed(title="Success!", description=f"You can now chat with the bot in <#{cid}>")
|
245 |
+
await message.reply(embed=embed)
|
246 |
+
return 0
|
247 |
+
else:
|
248 |
+
embed = discord.Embed(title="Error", description="Parameter `[channel]` is not in this guild. Use `--help` for command help.")
|
249 |
+
await message.reply(embed=embed)
|
250 |
+
return 0
|
251 |
+
else:
|
252 |
+
embed = discord.Embed(title="Error", description="Parameter `[channel]` is not in valid forms. Use `--help` for command help.")
|
253 |
+
await message.reply(embed=embed)
|
254 |
+
return 0
|
255 |
+
|
256 |
+
if message.content.startswith("--revoke"):
|
257 |
+
args = message.content.split()
|
258 |
+
del args[0]
|
259 |
+
if len(args) == 0:
|
260 |
+
with open(f"{guild_name}.guild", "r") as f:
|
261 |
+
k = f.read().split("\n")
|
262 |
+
cid = message.channel.id
|
263 |
+
if str(cid) in k:
|
264 |
+
k.remove(str(cid))
|
265 |
+
with open(f"{guild_name}.guild", "w") as f:
|
266 |
+
f.write("\n".join(k))
|
267 |
+
embed = discord.Embed(title="Success", description=f"Lyre is now unable to chat in <#{msgchannel.id}>")
|
268 |
+
await message.reply(embed=embed)
|
269 |
+
return 0
|
270 |
+
else:
|
271 |
+
embed = discord.Embed(title="Error", description=f"Lyre was already unable to chat in <#{msgchannel.id}>")
|
272 |
+
await message.reply(embed=embed)
|
273 |
+
return 0
|
274 |
+
if args[0] == "":
|
275 |
+
embed = discord.Embed(title="Error", description="Parameter `[channel]` empty. Use `--help` for command help.")
|
276 |
+
await message.reply(embed=embed)
|
277 |
+
return 0
|
278 |
+
if args[0].startswith("<#") and args[0].endswith(">"):
|
279 |
+
try:
|
280 |
+
cid = int(args[0][2:-1])
|
281 |
+
except:
|
282 |
+
embed = discord.Embed(title="Error", description="Parameter `[channel]` invalid. Use `--help` for command help.")
|
283 |
+
await message.reply(embed=embed)
|
284 |
+
return 0
|
285 |
+
with open(f"{guild_name}.guild", "r") as f:
|
286 |
+
k = f.read().split("\n")
|
287 |
+
if str(cid) in k:
|
288 |
+
k.remove(str(cid))
|
289 |
+
with open(f"{guild_name}.guild", "w") as f:
|
290 |
+
f.write("\n".join(k))
|
291 |
+
embed = discord.Embed(title="Success", description=f"Lyre is now unable to chat in {args[0]}")
|
292 |
+
await message.reply(embed=embed)
|
293 |
+
return 0
|
294 |
+
else:
|
295 |
+
embed = discord.Embed(title="Error", description=f"Lyre was already unable to chat in {args[0]}")
|
296 |
+
await message.reply(embed=embed)
|
297 |
+
return 0
|
298 |
+
else:
|
299 |
+
embed = discord.Embed(title="Error", description="Parameter `[channel]` is not in valid forms, or does not exist. Use `--help` for command help.")
|
300 |
+
await message.reply(embed=embed)
|
301 |
+
return 0
|
302 |
|
303 |
if message.content.startswith("--reset"):
|
304 |
args = message.content.split()
|
|
|
374 |
message.content = message.content.replace(f"<@{user.id}>",
|
375 |
f"<@{str(user)}>")
|
376 |
try:
|
377 |
+
info = requests.get("https://raw.githubusercontent.com/aryananumula/lr/main/info.json").content
|
378 |
+
bannedUsers = json.loads(info)["bannedUsers"]
|
379 |
+
imageModel = json.loads(info)["imageModel"]
|
380 |
+
userTimes = json.loads(info)["userTimes"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
381 |
s = f":green[{message.author}]: :violet[{message.content}] :blue[{msgchannel_name}] :orange[{guild_name}]"
|
382 |
if message.author == client.user:
|
383 |
return
|
|
|
456 |
context = f.read()
|
457 |
with open(f"{guild_name}.guild", "r") as f:
|
458 |
o = f.read()
|
459 |
+
try:
|
460 |
+
with open(f"usrtime/{message.author}", "r") as f:
|
461 |
+
er = f.read()
|
462 |
+
except:
|
463 |
+
with open(f"usrtime/{message.author}", "w") as f:
|
464 |
+
f.write(str(round(time.time())))
|
465 |
+
er = 0
|
466 |
+
y = round(time.time()) - int(er)
|
467 |
+
print(y)
|
468 |
+
if str(message.author).lower() not in userTimes.keys():
|
469 |
+
usrTime = 5
|
470 |
+
else:
|
471 |
+
usrTime = userTimes[str(message.author).lower()]
|
472 |
+
if message.author.id in bannedUsers:
|
473 |
+
return 0
|
474 |
+
if y < usrTime:
|
475 |
+
return 0
|
476 |
if (str(message.channel.id) in o.split("\n")) or (guild_name == "Direct"):
|
477 |
with open(f"usrtime/{message.author}", "w") as f:
|
478 |
f.write(str(round(time.time())))
|