Skip to content

Commit

Permalink
Merge pull request #163 from AlfredDiscordBot/development
Browse files Browse the repository at this point in the history
Shifting to nextcord 2.4.0
  • Loading branch information
alvinbengeorge authored Feb 26, 2023
2 parents fe270e3 + af2558a commit f2af86e
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 2,121 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Lint with black
run: |
black --check .
python -m pip install black
black --check ./*/*.py
1 change: 0 additions & 1 deletion cogs/ChatBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def __init__(self, CLIENT: commands.Bot, WOLFRAM):

def moderate_variables(self, guild_id, input_text, output):
if len(self.past_response[guild_id]) >= 50:

self.past_response[guild_id].pop(0)
self.generated[guild_id].pop(0)
self.past_response[guild_id].append(input_text)
Expand Down
4 changes: 2 additions & 2 deletions cogs/Games.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def requirements():
return ["FFMPEG_OPTIONS", "ydl_op"]
return ["FFMPEG_OPTIONS"]


class HangMan:
Expand Down Expand Up @@ -179,7 +179,7 @@ async def confirm(self, button: Button, inter: nextcord.Interaction):


class Games(commands.Cog, description="Very Simple Games"):
def __init__(self, CLIENT: commands.Bot, FFMPEG_OPTIONS, ydl_op):
def __init__(self, CLIENT: commands.Bot, FFMPEG_OPTIONS):
self.CLIENT = CLIENT
self.FFMPEG_OPTIONS = FFMPEG_OPTIONS
self.choices = [
Expand Down
7 changes: 5 additions & 2 deletions cogs/Topgg.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ def __init__(self, CLIENT: commands.Bot):

@tasks.loop(minutes=30)
async def loop(self):
await self.CLIENT.wait_until_ready()
await self.topgg.post_stats(self.CLIENT)
try:
await self.CLIENT.wait_until_ready()
await self.topgg.post_stats(self.CLIENT)
except:
print("TopGG not updated")


def setup(client, **i):
Expand Down
52 changes: 1 addition & 51 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
get_youtube_url,
svg2png,
cog_requirements,
ydl_op,
color as cc,
)

Expand All @@ -56,7 +55,6 @@ def fix():
fix()
# keep_alive()
location_of_file = os.getcwd()
ydl_copy = ydl_op.copy()
start_time = time.time()
mspace: dict = {}
deathrate: dict = {}
Expand Down Expand Up @@ -271,59 +269,11 @@ async def send_file_loop():
@tasks.loop(minutes=30)
async def youtube_loop():
return
print("Youtube_loop")
for i, l in config["youtube"].items():
await asyncio.sleep(2)
for j in l:
try:
if j[0] not in youtube_cache:
a = await get_youtube_url(j[0])
youtube_cache[j[0]] = a
else:
a = youtube_cache[j[0]]
if a[0] in ["https://www.youtube.com/", "https://www.youtube.com"]:
return
if not old_youtube_vid.get(i, None):
old_youtube_vid[i] = {}
if not old_youtube_vid[i].get(j[0], None):
old_youtube_vid[i][j[0]] = ""
if old_youtube_vid[i][j[0]] == a[0]:
continue
old_youtube_vid[i][j[0]] = a[0]
try:
message = j[1]
send_channel = CLIENT.get_channel(i)
if not send_channel:
del config["youtube"][i]
await send_channel.send(
embed=cembed(
title="New Video out",
description=f"New Video from {j[0]}",
url=a[0],
color=cc(re, send_channel.guild),
thumbnail=send_channel.guild.icon.url,
)
)
await send_channel.send(a[0] + "\n" + message)
except Exception:
await CLIENT.get_channel(DEV_CHANNEL).send(
embed=cembed(
title="Error in youtube_loop",
description=f"{str(traceback.format_exc())}\nSomething is wrong with channel no. {i}",
color=re[8],
)
)
except Exception as e:
if isinstance(e, aiohttp.client_exceptions.InvalidURL):
del config["youtube"][i]
print(i)
print(traceback.format_exc())
youtube_cache.clear()
print("Done")


@tasks.loop(minutes=5)
async def dev_loop():
await get_async("https://redditAPI.alvinbengeorge.repl.co")
await CLIENT.change_presence(activity=activities(CLIENT))


Expand Down
1,999 changes: 0 additions & 1,999 deletions poetry.lock

This file was deleted.

35 changes: 0 additions & 35 deletions pyproject.toml

This file was deleted.

Binary file modified requirements.txt
Binary file not shown.
32 changes: 3 additions & 29 deletions utils/External_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,7 @@
import urllib
import urllib.parse
import utils.assets as assets
import youtube_dl

ydl_op = {
"format": "bestaudio/best",
"postprocessors": [
{
"key": "FFmpegExtractAudio",
"preferredcodec": "mp3",
"preferredquality": "384",
}
],
"noplaylist": "True",
}

SVG2PNG_API_URI = os.getenv("svg2pnguri")
SVG2PNG_API_TOKEN = os.getenv("svg2pngtoken")

Expand Down Expand Up @@ -93,13 +81,6 @@ def activities(client, FORCED_ACTIVITY=None):
return random.choice(all_activities)


@lru_cache(maxsize=512)
def youtube_info(url):
with youtube_dl.YoutubeDL(ydl_op) as ydl:
info = ydl.extract_info(url, download=False)
return info


def timestamp(i):
return datetime.fromtimestamp(i)

Expand Down Expand Up @@ -320,13 +301,13 @@ async def imdb_embed(movie: str, color: int):

async def redd(ctx, account: str = "wholesomememes", number: int = 25):
a = await get_async(
f"https://meme-api.herokuapp.com/gimme/{account}/{number}", kind="json"
f"https://redditAPI.alvinbengeorge.repl.co/meme/{account}", kind="json"
)
embeds = []
bot = getattr(ctx, "bot", getattr(ctx, "client", None))
if "message" in a.keys():
return [cembed(title="Oops", description=a["message"], color=bot.re[8])]
memes = a["memes"]
memes = a
for i in memes:
embed = cembed(
title=i["title"],
Expand Down Expand Up @@ -410,13 +391,6 @@ def reset_emo(client):
return emo


def youtube_download(url: str):
with youtube_dl.YoutubeDL(ydl_op) as ydl:
info = ydl.extract_info(url, download=False)
URL = info["formats"][0]["url"]
return URL


def subtract_list(l1: List, l2: List):
a = []
for i in l1:
Expand Down
1 change: 0 additions & 1 deletion utils/inshort.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ async def getNews(category):
return newsDictionary

for index, card in enumerate(newsCards):

try:
title = card.find(class_="news-card-title").find("a").text.strip()
except AttributeError:
Expand Down

0 comments on commit f2af86e

Please sign in to comment.