mirror of
https://github.com/Fluffy-Bean/Lynxie.git
synced 2025-05-14 08:02:17 +00:00
Clean up code
This commit is contained in:
parent
90a347eb0b
commit
c359356f4b
10 changed files with 51 additions and 36 deletions
0
lynxie/__init__.py
Normal file
0
lynxie/__init__.py
Normal file
|
@ -53,11 +53,6 @@ async def on_message_edit(before, after):
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
# await before.channel.send(
|
|
||||||
# f"@{before.author} edited their message!!!\n"
|
|
||||||
# f'"{before.content}" --> "{after.content}"'
|
|
||||||
# )
|
|
||||||
|
|
||||||
|
|
||||||
async def run():
|
async def run():
|
||||||
async with lynxie:
|
async with lynxie:
|
||||||
|
|
12
lynxie/commands/e621.py
Normal file
12
lynxie/commands/e621.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import requests
|
||||||
|
|
||||||
|
from discord.ext import commands
|
||||||
|
|
||||||
|
|
||||||
|
class E621(commands.Cog):
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
async def e621(self, ctx):
|
||||||
|
await ctx.reply(f":3")
|
|
@ -1,3 +1,4 @@
|
||||||
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,4 +8,10 @@ class Hello(commands.Cog):
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def hello(self, ctx):
|
async def hello(self, ctx):
|
||||||
await ctx.send(f"Hello from England, {ctx.author.mention}!")
|
embed = discord.Embed(
|
||||||
|
title="Hello!",
|
||||||
|
description="I'm Lynxie, a multipurpose Discord bot written in Python!",
|
||||||
|
color=discord.Color.orange(),
|
||||||
|
)
|
||||||
|
|
||||||
|
await ctx.reply(embed=embed)
|
||||||
|
|
|
@ -14,7 +14,8 @@ class Help(commands.Cog):
|
||||||
"play <url>": "Play a song from YouTube, SoundCloud, etc.",
|
"play <url>": "Play a song from YouTube, SoundCloud, etc.",
|
||||||
"stop": "Stop the current song and leave the voice channel",
|
"stop": "Stop the current song and leave the voice channel",
|
||||||
"animal <animal>": "Get a random image of an animal!",
|
"animal <animal>": "Get a random image of an animal!",
|
||||||
"overlay <style>": "Overlay an image with a style, e.g. `bubble`",
|
"overlay <image> <style>": "Overlay an image with a style, e.g. `bubble mask`",
|
||||||
|
"saveable": "Turn image into a GIF to save within Discord",
|
||||||
}
|
}
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
|
|
|
@ -86,7 +86,7 @@ class Img(commands.Cog):
|
||||||
|
|
||||||
width, height = image_attachments.width, image_attachments.height
|
width, height = image_attachments.width, image_attachments.height
|
||||||
if not 10 < width <= 4500 or not 10 < height <= 4500:
|
if not 10 < width <= 4500 or not 10 < height <= 4500:
|
||||||
error = "Image must be at least 10x10 and under 4500x4500!"
|
error = "Image must be at least over 10x10 and under 4500x4500!"
|
||||||
await ctx.reply(embed=error_message(error))
|
await ctx.reply(embed=error_message(error))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -24,20 +24,24 @@ class Music(commands.Cog):
|
||||||
async with ctx.typing():
|
async with ctx.typing():
|
||||||
try:
|
try:
|
||||||
song_info = ytdl.extract_info(url, download=False)
|
song_info = ytdl.extract_info(url, download=False)
|
||||||
print(song_info["url"])
|
|
||||||
ctx.voice_client.play(
|
ctx.voice_client.play(
|
||||||
discord.FFmpegPCMAudio(song_info["url"], **ffmpeg_options)
|
discord.FFmpegPCMAudio(song_info["url"], **ffmpeg_options)
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception as err:
|
||||||
|
error = "An error occurred while processing this request." + str(err)
|
||||||
await ctx.reply(
|
await ctx.reply(
|
||||||
embed=error_message(
|
embed=error_message(error),
|
||||||
"An error occurred while processing this request."
|
|
||||||
),
|
|
||||||
mention_author=False,
|
mention_author=False,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
await ctx.send(f"Now playing: {song_info['title']}")
|
embed = discord.Embed(
|
||||||
|
title="Now playing",
|
||||||
|
description=f"[{song_info['title']}]({song_info['webpage_url']})",
|
||||||
|
color=discord.Color.orange(),
|
||||||
|
)
|
||||||
|
|
||||||
|
await ctx.reply(embed=embed, mention_author=False)
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def stop(self, ctx):
|
async def stop(self, ctx):
|
||||||
|
@ -49,9 +53,11 @@ class Music(commands.Cog):
|
||||||
if ctx.author.voice:
|
if ctx.author.voice:
|
||||||
await ctx.author.voice.channel.connect()
|
await ctx.author.voice.channel.connect()
|
||||||
else:
|
else:
|
||||||
|
error = "You are not connected to a voice channel."
|
||||||
await ctx.reply(
|
await ctx.reply(
|
||||||
embed=error_message("You are not connected to a voice channel!"),
|
embed=error_message(error),
|
||||||
mention_author=False,
|
mention_author=False,
|
||||||
)
|
)
|
||||||
|
return
|
||||||
elif ctx.voice_client.is_playing():
|
elif ctx.voice_client.is_playing():
|
||||||
ctx.voice_client.stop()
|
ctx.voice_client.stop()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,4 +8,9 @@ class Ping(commands.Cog):
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def ping(self, ctx):
|
async def ping(self, ctx):
|
||||||
await ctx.send(f"Pong! {round(self.bot.latency * 1000)}ms")
|
embed = discord.Embed(
|
||||||
|
title="Pong!",
|
||||||
|
description=f"{round(self.bot.latency * 1000)}ms",
|
||||||
|
color=discord.Color.orange(),
|
||||||
|
)
|
||||||
|
await ctx.reply(embed=embed, mention_author=False)
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import os
|
import os
|
||||||
|
import dotenv
|
||||||
from discord import Object
|
from discord import Object
|
||||||
from lynxie.utils import get_env_or_error
|
|
||||||
|
|
||||||
DISCORD_TOKEN = get_env_or_error("DISCORD_TOKEN")
|
DISCORD_TOKEN = dotenv.dotenv_values(".env").get("DISCORD_TOKEN") or os.environ.get("DISCORD_TOKEN") or None
|
||||||
DISCORD_GUILD_ID = Object(id=1040757387033849976)
|
DISCORD_GUILD_ID = Object(id=1040757387033849976)
|
||||||
LYNXIE_PREFIX = "?"
|
LYNXIE_PREFIX = "?"
|
||||||
|
|
||||||
DATA_PATH = "data"
|
DATA_PATH = os.path.join("lynxie", "data")
|
||||||
ASSETS_PATH = "assets"
|
ASSETS_PATH = os.path.join("lynxie", "assets")
|
||||||
|
|
||||||
DATABASE_URI = f"sqlite:///" + os.path.join(DATA_PATH, "lynxie.db")
|
DATABASE_URI = f"sqlite:///" + os.path.join(DATA_PATH, "lynxie.db")
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
import dotenv
|
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord.gateway import _log
|
from discord.gateway import _log
|
||||||
|
from lynxie.config import LYNXIE_PREFIX
|
||||||
|
|
||||||
|
|
||||||
async def mobile_status(self):
|
async def mobile_status(self):
|
||||||
|
@ -53,19 +51,9 @@ def error_message(error: str) -> discord.Embed:
|
||||||
title="Error :(",
|
title="Error :(",
|
||||||
description=error,
|
description=error,
|
||||||
colour=discord.Colour.red(),
|
colour=discord.Colour.red(),
|
||||||
|
).set_footer(
|
||||||
|
text=f"For more information, use the "
|
||||||
|
f"{LYNXIE_PREFIX}help command."
|
||||||
)
|
)
|
||||||
embed.set_footer(text="For more information, use the help command.")
|
|
||||||
|
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
|
|
||||||
def get_env_or_error(env: str) -> str:
|
|
||||||
from_file = dotenv.dotenv_values(".env").get(env)
|
|
||||||
from_env = os.environ.get(env)
|
|
||||||
|
|
||||||
if from_file is None and from_env is None:
|
|
||||||
raise KeyError(f"Environment variable {env} not found")
|
|
||||||
if from_file is None:
|
|
||||||
return from_env
|
|
||||||
else:
|
|
||||||
return from_file
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue