mirror of
https://github.com/polyjitter/searchbot-discord.git
synced 2024-08-14 22:46:55 +00:00
Added empty prefix handling
This commit is contained in:
parent
f524d547a8
commit
c24447b0e2
1 changed files with 16 additions and 5 deletions
19
main.py
19
main.py
|
@ -45,13 +45,21 @@ class Bot(commands.Bot):
|
||||||
print(msg)
|
print(msg)
|
||||||
|
|
||||||
async def on_message(self, message):
|
async def on_message(self, message):
|
||||||
|
mentions = [self.user.mention, f'<@!{bot.user.id}>']
|
||||||
|
ctx = await self.get_context(message)
|
||||||
|
|
||||||
if message.author.bot:
|
if message.author.bot:
|
||||||
return
|
return
|
||||||
if message.author.id in self.config.get('BLOCKED'):
|
elif message.author.id in self.config.get('BLOCKED'):
|
||||||
return
|
return
|
||||||
if (self.maintenance):
|
elif self.maintenance and not message.author.is_owner():
|
||||||
return
|
return
|
||||||
await self.get_context(message)
|
elif message.content in mentions:
|
||||||
|
assist_msg = (
|
||||||
|
"**Hi there! How can I help?**\n\n"
|
||||||
|
f"You may use **{self.user.mention}` term here`** to search, or **{self.user.mention}` help`** for assistance.")
|
||||||
|
await ctx.send(assist_msg)
|
||||||
|
else:
|
||||||
await self.process_commands(message)
|
await self.process_commands(message)
|
||||||
|
|
||||||
bot = Bot(
|
bot = Bot(
|
||||||
|
@ -121,6 +129,9 @@ async def search_logic(query: str, type: str = None):
|
||||||
# Create the URL to make an API call to
|
# Create the URL to make an API call to
|
||||||
call = f'{instance}/search?q={query}&format=json&language=en-US'
|
call = f'{instance}/search?q={query}&format=json&language=en-US'
|
||||||
|
|
||||||
|
if type:
|
||||||
|
call += f'?type={type}'
|
||||||
|
|
||||||
# Make said API call
|
# Make said API call
|
||||||
try:
|
try:
|
||||||
async with bot.session.get(call) as resp:
|
async with bot.session.get(call) as resp:
|
||||||
|
@ -185,7 +196,7 @@ async def instance_check(instance, info):
|
||||||
# Reached if passes all checks
|
# Reached if passes all checks
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@bot.listen("on_command_error")
|
@bot.listen()
|
||||||
async def on_command_error(ctx, error):
|
async def on_command_error(ctx, error):
|
||||||
|
|
||||||
if isinstance(error, commands.CommandNotFound):
|
if isinstance(error, commands.CommandNotFound):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue