CryptoScoutv1
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -39,6 +39,8 @@ intents = discord.Intents.default()
|
|
39 |
intents.message_content = True
|
40 |
bot = commands.Bot(command_prefix="/", intents=intents)
|
41 |
|
|
|
|
|
42 |
## BOT COMMANDS ##
|
43 |
|
44 |
@bot.event
|
@@ -59,17 +61,21 @@ thread_to_user = {}
|
|
59 |
|
60 |
## /echo command to return the llm repsonse ##
|
61 |
|
62 |
-
@bot.
|
63 |
-
async def
|
64 |
if ctx.author.id == bot.user.id:
|
65 |
return
|
|
|
66 |
try:
|
67 |
-
#
|
68 |
-
|
|
|
|
|
|
|
69 |
|
70 |
loop = asyncio.get_running_loop()
|
71 |
client = await loop.run_in_executor(None, get_client, None)
|
72 |
-
job = client.submit(prompt, api_name="/predict")
|
73 |
await wait(job)
|
74 |
|
75 |
try:
|
@@ -80,7 +86,7 @@ async def chat(ctx, prompt: str):
|
|
80 |
await ctx.send("The gradio space powering this bot is really busy! Please try again later!")
|
81 |
except Exception as e:
|
82 |
print(f"{e}")
|
83 |
-
|
84 |
@bot.hybrid_command(name="cshelp", description="Get information on how to use this bot.")
|
85 |
async def help_command(ctx):
|
86 |
help_message = """
|
@@ -91,18 +97,6 @@ async def help_command(ctx):
|
|
91 |
"""
|
92 |
await ctx.send(help_message)
|
93 |
|
94 |
-
@bot.hybrid_command(name="sentences", description="Choose a predefined sentence.")
|
95 |
-
async def sentences_command(ctx):
|
96 |
-
sentences_list = [
|
97 |
-
("sentence1", "value1"),
|
98 |
-
("sentence2", "value2"),
|
99 |
-
("sentence3", "value3"),
|
100 |
-
# Add more sentences and values as needed
|
101 |
-
]
|
102 |
-
|
103 |
-
for sentence, value in sentences_list:
|
104 |
-
await ctx.send(f"{sentence} - {value}")
|
105 |
-
|
106 |
@bot.event
|
107 |
async def on_message(message):
|
108 |
if message.author.bot:
|
@@ -118,4 +112,55 @@ def run_bot():
|
|
118 |
else:
|
119 |
bot.run(DISCORD_TOKEN)
|
120 |
|
121 |
-
threading.Thread(target=run_bot).start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
intents.message_content = True
|
40 |
bot = commands.Bot(command_prefix="/", intents=intents)
|
41 |
|
42 |
+
|
43 |
+
|
44 |
## BOT COMMANDS ##
|
45 |
|
46 |
@bot.event
|
|
|
61 |
|
62 |
## /echo command to return the llm repsonse ##
|
63 |
|
64 |
+
@bot.slash_command(name="cryptotrend", description="Find top trending cryptocurrencies for a specific period.")
|
65 |
+
async def cryptotrend(ctx, period: str = commands.Param(choices=["day", "week", "month"])):
|
66 |
if ctx.author.id == bot.user.id:
|
67 |
return
|
68 |
+
|
69 |
try:
|
70 |
+
# Process the period parameter to create a suitable prompt
|
71 |
+
prompt = f"Find me the top trending cryptocurrencies this {period}"
|
72 |
+
|
73 |
+
# Acknowledge the command immediately
|
74 |
+
await ctx.send(f"Processing for: {period}")
|
75 |
|
76 |
loop = asyncio.get_running_loop()
|
77 |
client = await loop.run_in_executor(None, get_client, None)
|
78 |
+
job = client.submit(prompt, api_name="/predict") # Use the prompt with the period parameter
|
79 |
await wait(job)
|
80 |
|
81 |
try:
|
|
|
86 |
await ctx.send("The gradio space powering this bot is really busy! Please try again later!")
|
87 |
except Exception as e:
|
88 |
print(f"{e}")
|
89 |
+
|
90 |
@bot.hybrid_command(name="cshelp", description="Get information on how to use this bot.")
|
91 |
async def help_command(ctx):
|
92 |
help_message = """
|
|
|
97 |
"""
|
98 |
await ctx.send(help_message)
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
@bot.event
|
101 |
async def on_message(message):
|
102 |
if message.author.bot:
|
|
|
112 |
else:
|
113 |
bot.run(DISCORD_TOKEN)
|
114 |
|
115 |
+
threading.Thread(target=run_bot).start()
|
116 |
+
|
117 |
+
event.wait()
|
118 |
+
if not DISCORD_TOKEN:
|
119 |
+
welcome_message = """
|
120 |
+
## You have not specified a DISCORD_TOKEN, which means you have not created a bot account. Please follow these steps:
|
121 |
+
### 1. Go to https://discord.com/developers/applications and click 'New Application'
|
122 |
+
|
123 |
+
### 2. Give your bot a name 🤖
|
124 |
+
![](https://gradio-builds.s3.amazonaws.com/demo-files/discordbots/BotName.png)
|
125 |
+
|
126 |
+
## 3. In Settings > Bot, click the 'Reset Token' button to get a new token. Write it down and keep it safe 🔐
|
127 |
+
|
128 |
+
![](https://gradio-builds.s3.amazonaws.com/demo-files/discordbots/ResetToken.png)
|
129 |
+
|
130 |
+
## 4. Optionally make the bot public if you want anyone to be able to add it to their servers
|
131 |
+
|
132 |
+
## 5. Scroll down and enable 'Message Content Intent' under 'Priviledged Gateway Intents'
|
133 |
+
|
134 |
+
![](https://gradio-builds.s3.amazonaws.com/demo-files/discordbots/MessageContentIntent.png)
|
135 |
+
## 6. Save your changes!
|
136 |
+
## 7. The token from step 3 is the DISCORD_TOKEN. Rerun the deploy_discord command, e.g client.deploy_discord(discord_bot_token=DISCORD_TOKEN, ...), or add the token as a space secret manually.
|
137 |
+
"""
|
138 |
+
else:
|
139 |
+
permissions = Permissions(326417525824)
|
140 |
+
url = oauth_url(bot.user.id, permissions=permissions)
|
141 |
+
welcome_message = f"""
|
142 |
+
## Add this bot to your server by clicking this link:
|
143 |
+
|
144 |
+
{url}
|
145 |
+
## How to use it?
|
146 |
+
The bot can be triggered via `!echo` followed by your text prompt.
|
147 |
+
## Enabling slash commands
|
148 |
+
If you are the owner of this bot, call the `!sync` command from your discord server.
|
149 |
+
This will allow anyone in your server to call the bot via `/echo`.
|
150 |
+
This is known as a slash command and is a nicer experience than calling the bot via `!echo`.
|
151 |
+
|
152 |
+
After calling `!sync`, it may take a few minutes for `/echo` to be recognized as a valid command
|
153 |
+
in your server.
|
154 |
+
⚠️ Note ⚠️: It is best to create a separate bot per command if you intend to use slash commands. Also make sure
|
155 |
+
none of your bots have matching command names.
|
156 |
+
"""
|
157 |
+
|
158 |
+
|
159 |
+
with gr.Blocks() as demo:
|
160 |
+
gr.Markdown(
|
161 |
+
f"""
|
162 |
+
# Discord bot of TITLE HERE
|
163 |
+
{welcome_message}
|
164 |
+
"""
|
165 |
+
)
|
166 |
+
demo.launch()
|