clean code for #23

This commit is contained in:
Milka64 2020-12-13 16:51:19 +01:00
parent 283a3919f0
commit 29de2a539a

View file

@ -46,7 +46,10 @@ logger.addHandler(stream_handler)
class Mybot(commands.Cog): class Mybot(commands.Cog):
#Fonctions necesaires pour Kabot. #Fonctions necesaires pour Kabot.
def __init__(self, bot): def __init__(self, bot, gl_url=None, gl_token=None, gif_token=None):
self.gl_url = gl_url
self.gl_token = gl_token
self.gif_token = gif_token
self.bot = bot self.bot = bot
self.sounds = [] self.sounds = []
self.sounds_history = [] self.sounds_history = []
@ -74,8 +77,9 @@ class Mybot(commands.Cog):
@commands.command(help='list des commits') @commands.command(help='list des commits')
async def commits(self, ctx, number = 5): async def commits(self, ctx, number = 5):
if self.gl_url and self.gl_token:
number = int(number) number = int(number)
gl = gitlab.Gitlab('https://git.0w.tf/', private_token='s-e3HXBUTroL52cNkAbe') gl = gitlab.gitlab(self.gl_url, self.gl_token)
gl.auth() gl.auth()
projects = gl.projects.list(search='Kabot')[0] projects = gl.projects.list(search='Kabot')[0]
commits = projects.commits.list(all=True)[:number] commits = projects.commits.list(all=True)[:number]
@ -97,9 +101,10 @@ class Mybot(commands.Cog):
@commands.command(help="Interrogation issues \n Args: list, search[mot clé] et add[nom de l'issue]") @commands.command(help="Interrogation issues \n Args: list, search[mot clé] et add[nom de l'issue]")
async def issue(self, ctx, *args): async def issue(self, ctx, *args):
if self.gl_url and self.gl_token:
if args: if args:
args = list(args) args = list(args)
gl = gitlab.Gitlab('https://git.0w.tf/', private_token='s-e3HXBUTroL52cNkAbe') gl = gitlab.gitlab(self.gl_url, self.gl_token)
gl.auth() gl.auth()
if args[0] == 'list': if args[0] == 'list':
projects = gl.projects.list(search='Kabot')[0] projects = gl.projects.list(search='Kabot')[0]
@ -205,8 +210,9 @@ class Mybot(commands.Cog):
query = ctx.message.content.replace('!gif ', '') query = ctx.message.content.replace('!gif ', '')
print(query) print(query)
api_instance = giphy_client.DefaultApi() api_instance = giphy_client.DefaultApi()
api_key = "udhL9Rgdme3HpAoFhWVZoYM0l0XwkzLz" api_key = self.gif_token
lang = 'fr' lang = 'fr'
if api_key:
try: try:
api_response = api_instance.gifs_search_get(api_key, query, lang=lang, limit=15) api_response = api_instance.gifs_search_get(api_key, query, lang=lang, limit=15)
api_response.to_dict()['data'][0] api_response.to_dict()['data'][0]
@ -215,6 +221,9 @@ class Mybot(commands.Cog):
await ctx.channel.send(get_url['url']) await ctx.channel.send(get_url['url'])
except ApiException as e: except ApiException as e:
await ctx.channel.send("Exception when calling DefaultApi->gifs_search_get: %s\n" % e) await ctx.channel.send("Exception when calling DefaultApi->gifs_search_get: %s\n" % e)
else:
await ctx.channel.send("Exception : No api key found")
@commands.guild_only() @commands.guild_only()
@commands.command() @commands.command()
@ -526,7 +535,15 @@ def get_word(word_type):
def main(): def main():
logger.info("Initialisation de Kabot") logger.info("Initialisation de Kabot")
token = "NjI3MTM3NDY1MDA5ODMxOTQ2.Xxl5dg.-eXs6op39SyB1psp4QZIXv7kPuY" token = "NjI3MTM3NDY1MDA5ODMxOTQ2.Xxl5dg.-eXs6op39SyB1psp4QZIXv7kPuY"
bot = commands.Bot(command_prefix='!') gl_url = 'https://git.0w.tf/'
gl_token='s-e3HXBUTroL52cNkAbe'
gif_token = "udhL9Rgdme3HpAoFhWVZoYM0l0XwkzLz"
bot = commands.Bot(
command_prefix='!',
gl_url=gl_url,
gl_token=gl_token,
gif_token=git_token
)
test = False test = False
if "test" in argv[-1]: if "test" in argv[-1]: