-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
95 lines (80 loc) · 2.79 KB
/
bot.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
import discord
from discord.ext import commands
from colorama import Back, Style
from addonsearch import addonsearch
from schematicsearch import schematicsearch
import dotenv
import os
dotenv.load_dotenv()
intents = discord.Intents.default()
intents.message_content = True # Required for reading user messages
bot = commands.Bot(command_prefix="??", intents=intents)
bot.remove_command("help")
@bot.event
async def on_ready():
print(f"{Back.GREEN}Logged in as {bot.user}{Style.RESET_ALL}")
@bot.command()
async def help(ctx):
embed = discord.Embed(
title="Commands available",
description="Addons & Schematics commands",
color=discord.Color.blurple()
)
embed.add_field(
name="Addon Commands",
value="??addon search <query> [how many default=1] - Search for addons on Blueprint.",
inline=False
)
embed.add_field(
name="Schematic Commands",
value="??schematic search <query> [how many default=1]",
inline=False
)
embed.add_field(
name="Data types",
value="""
<> - needed
[] - optional
""",
inline=False
)
await ctx.reply(embed=embed)
# Create "addon" group command
@bot.group(invoke_without_command=True)
async def addon(ctx):
await ctx.send("Use `??addon search <query>` to find addons.")
@bot.group(invoke_without_command=True)
async def schematic(ctx):
await ctx.send("Use `??schematic search <query>` to find schematics.")
# Subcommand for "addon"
@addon.command()
async def search(ctx, *, query: str):
# Extract the number of results from the end of the query (if available)
parts = query.split()
if parts[-1].isdigit():
limit = int(parts[-1])
query = " ".join(parts[:-1]) # Remove the number from the query
else:
limit = 1 # Default to 1 result if no number is specified
# Ensure the limit is between 1 and 5
limit = max(1, min(limit, 5))
msg = await ctx.send(f"Searching for {limit} addon(s) related to: `{query}`")
await msg.delete(delay=3)
await addonsearch(ctx=ctx, query=query, limit=limit)
# Subcommand for "schematic"
@schematic.command()
async def search(ctx, *, query: str):
# Extract the number of results from the end of the query (if available)
parts = query.split()
if parts[-1].isdigit():
limit = int(parts[-1])
query = " ".join(parts[:-1]) # Remove the number from the query
else:
limit = 1 # Default to 1 result if no number is specified
# Ensure the limit is between 1 and 5
limit = max(1, min(limit, 5))
msg = await ctx.send(f"Searching for {limit} schematic(s) related to: `{query}`")
await msg.delete(delay=3)
# Fetch data
await schematicsearch(ctx=ctx, query=query, limit=limit)
bot.run(os.getenv("TOKEN"))