From 7c1c34272a3a9da1b644920a77aa213e2a05da53 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 7 Jun 2021 22:08:35 +0200 Subject: [PATCH] better import --- src/cogs/confreriedukassoulait.py | 6 ++---- src/cogs/fun.py | 4 ++-- src/cogs/internet.py | 4 ++-- src/cogs/utils.py | 18 ++++++++---------- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/cogs/confreriedukassoulait.py b/src/cogs/confreriedukassoulait.py index 2075c7b..cb2d5c1 100644 --- a/src/cogs/confreriedukassoulait.py +++ b/src/cogs/confreriedukassoulait.py @@ -1,9 +1,7 @@ import discord -import re -import os +from re import findall from discord.ext import commands from random import choice -customTimezone = os.environ['TIMEZONE'] from utils.core import userOrNick from utils.time import nowCustom, intToDatetime, nowUTC, timestampScreen from cogs.internet import Internet @@ -79,7 +77,7 @@ class ConfrerieDuKassoulait(commands.Cog): if not ( message.content.startswith(f"{prefix}note") or message.content.startswith(f"{prefix}memo") or - len(re.findall(".com/channels/", message.content)) != 0 or + len(findall(".com/channels/", message.content)) != 0 or self.client.user.id is message.author.id ): user_suppressed = None diff --git a/src/cogs/fun.py b/src/cogs/fun.py index 7541f77..8c53864 100644 --- a/src/cogs/fun.py +++ b/src/cogs/fun.py @@ -1,5 +1,5 @@ import discord -import re +from re import findall from discord.ext import commands from random import randint, choice from datetime import timedelta @@ -161,7 +161,7 @@ class Fun(commands.Cog): final_message = message.content suite_auteur = message.author - urls = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', final_message) + urls = findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', final_message) for i in range (0, len(urls)): final_message = final_message.replace(urls[i], '') diff --git a/src/cogs/internet.py b/src/cogs/internet.py index 8143faa..b99d794 100644 --- a/src/cogs/internet.py +++ b/src/cogs/internet.py @@ -1,6 +1,6 @@ import discord import feedparser -import os +from os import environ from discord.ext import commands from random import choice from asyncpraw import Reddit @@ -37,7 +37,7 @@ class Internet(commands.Cog): '2meirl4meirl', 'AdviceAnimals', 'weirdmemes']) try: - async with Reddit(client_id = os.environ['TOKEN_REDDIT_CLIENT_ID'], client_secret = os.environ['TOKEN_REDDIT_CLIENT_SECRET'], user_agent = f"disreddit /u/{os.environ['TOKEN_REDDIT_USER_AGENT']}, http://localhost:8080") as reddit: + async with Reddit(client_id = environ['TOKEN_REDDIT_CLIENT_ID'], client_secret = environ['TOKEN_REDDIT_CLIENT_SECRET'], user_agent = f"disreddit /u/{environ['TOKEN_REDDIT_USER_AGENT']}, http://localhost:8080") as reddit: subreddit = await reddit.subreddit(subredditchoix) # récupération du subreddit hot = subreddit.top(limit = 20) # récupération des memes avec une limite aux 10 premiers memes all_subs = [item async for item in hot] # liste des memes diff --git a/src/cogs/utils.py b/src/cogs/utils.py index 88539c5..bab3081 100644 --- a/src/cogs/utils.py +++ b/src/cogs/utils.py @@ -1,13 +1,12 @@ import discord -import os -import re +from os import environ, path +from re import findall from discord.ext import commands, tasks from random import randint, shuffle from pytz import timezone from discord_slash import cog_ext from utils.reminder import Reminder -from utils.core import map_list_among_us, getURLsInString, getMentionInString, cleanCodeStringWithMentionAndURLs -from utils.core import cleanUser, userOrNick +from utils.core import map_list_among_us, getURLsInString, getMentionInString, cleanCodeStringWithMentionAndURLs, cleanUser, userOrNick from utils.time import stringTempsVersSecondes, nowUTC, intToDatetime, timedeltaToString, timestampScreen, getAge, ageLayout, nowCustom def setup(client): @@ -17,7 +16,7 @@ class Utils(commands.Cog): """Commandes essentielles.""" def __init__(self, client): self.client = client - self.customTimezone = os.environ['TIMEZONE'] + self.customTimezone = environ['TIMEZONE'] self._reminderLoop.start() @commands.command(name='ping') @@ -260,9 +259,8 @@ class Utils(commands.Cog): voice = len(voice_channels) nombreServeur = len(self.client.guilds) - with open(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "README.md"), "r") as file: - for versionNumber in re.findall(r'https://img.shields.io/badge/version-(\d+\.\d+)', file.readlines()[2]): - version = versionNumber + with open(path.join(path.dirname(path.dirname(path.dirname(__file__))), "README.md"), "r") as file: + version = findall(r'https://img.shields.io/badge/version-(\d+\.\d+)', file.readlines()[2])[0] embed.add_field(name = "Dev", value = f"[{appinfo.owner}](https://github.com/Mylloon)") embed.add_field(name = f"Serveur{'s' if nombreServeur > 1 else ''}", value = f"`{nombreServeur}`") @@ -398,7 +396,7 @@ class Utils(commands.Cog): args = list(args) if len(args) > 2: question = args[0] - for i in re.findall(r'\d+', question): + for i in findall(r'\d+', question): question = cleanUser(ctx, question, i) propositions = args[1:] if len(propositions) <= 20: @@ -465,7 +463,7 @@ class Utils(commands.Cog): titre = "Nouveau vote" else: # si titre défini titre = args[0] - for findedId in re.findall(r'\d+', titre): # récupération mention dans titre + for findedId in findall(r'\d+', titre): # récupération mention dans titre titre = cleanUser(ctx, titre, findedId) args = args[1:] embed = discord.Embed(title = titre, description = cleanCodeStringWithMentionAndURLs(args[0]), color = discord.Colour.random()).set_footer(text = f"Sondage de {userOrNick(ctx.author)}", icon_url = ctx.author.avatar_url)