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):
#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.sounds = []
self.sounds_history = []
@ -74,14 +77,15 @@ class Mybot(commands.Cog):
@commands.command(help='list des commits')
async def commits(self, ctx, number = 5):
number = int(number)
gl = gitlab.Gitlab('https://git.0w.tf/', private_token='s-e3HXBUTroL52cNkAbe')
gl.auth()
projects = gl.projects.list(search='Kabot')[0]
commits = projects.commits.list(all=True)[:number]
for commit in commits:
detail = commit.attributes
await ctx.channel.send("__" + detail['author_name'] + "__: " + detail['title'] + '\n' + detail['web_url'])
if self.gl_url and self.gl_token:
number = int(number)
gl = gitlab.gitlab(self.gl_url, self.gl_token)
gl.auth()
projects = gl.projects.list(search='Kabot')[0]
commits = projects.commits.list(all=True)[:number]
for commit in commits:
detail = commit.attributes
await ctx.channel.send("__" + detail['author_name'] + "__: " + detail['title'] + '\n' + detail['web_url'])
@commands.command(help='clear cache youtube dl')
async def cache_clear(self, ctx):
@ -97,34 +101,35 @@ class Mybot(commands.Cog):
@commands.command(help="Interrogation issues \n Args: list, search[mot clé] et add[nom de l'issue]")
async def issue(self, ctx, *args):
if args:
args = list(args)
gl = gitlab.Gitlab('https://git.0w.tf/', private_token='s-e3HXBUTroL52cNkAbe')
gl.auth()
if args[0] == 'list':
projects = gl.projects.list(search='Kabot')[0]
issues = projects.issues.list()
for issue in issues:
if "closed" == issue.state:
pass
else:
await ctx.channel.send('#' + str(issue.id) + ": " + issue.title + '\n' + issue.web_url)
elif args[0] == 'search':
query = ''.join(args[1:])
project = gl.projects.list(search='Kabot')[0]
find_issues = project.search("issues", query)
for issue in find_issues:
await ctx.channel.send("#" + str(issue['id']) + ": " + issue['title'] + '\n' + issue['web_url'])
elif args[0] == 'add':
title = ' '.join(args[1:])
author = title + ' - By ' + ctx.message.author.name
projects = gl.projects.list()
for project in projects:
if "Kabot" == project.name:
issue = project.issues.create({'title': author})
await ctx.channel.send(issue.web_url)
else:
await ctx.channel.send('unknown command')
if self.gl_url and self.gl_token:
if args:
args = list(args)
gl = gitlab.gitlab(self.gl_url, self.gl_token)
gl.auth()
if args[0] == 'list':
projects = gl.projects.list(search='Kabot')[0]
issues = projects.issues.list()
for issue in issues:
if "closed" == issue.state:
pass
else:
await ctx.channel.send('#' + str(issue.id) + ": " + issue.title + '\n' + issue.web_url)
elif args[0] == 'search':
query = ''.join(args[1:])
project = gl.projects.list(search='Kabot')[0]
find_issues = project.search("issues", query)
for issue in find_issues:
await ctx.channel.send("#" + str(issue['id']) + ": " + issue['title'] + '\n' + issue['web_url'])
elif args[0] == 'add':
title = ' '.join(args[1:])
author = title + ' - By ' + ctx.message.author.name
projects = gl.projects.list()
for project in projects:
if "Kabot" == project.name:
issue = project.issues.create({'title': author})
await ctx.channel.send(issue.web_url)
else:
await ctx.channel.send('unknown command')
@commands.command()
async def join(self, ctx):
@ -205,16 +210,20 @@ class Mybot(commands.Cog):
query = ctx.message.content.replace('!gif ', '')
print(query)
api_instance = giphy_client.DefaultApi()
api_key = "udhL9Rgdme3HpAoFhWVZoYM0l0XwkzLz"
api_key = self.gif_token
lang = 'fr'
try:
api_response = api_instance.gifs_search_get(api_key, query, lang=lang, limit=15)
api_response.to_dict()['data'][0]
get_url = random.choice(api_response.to_dict()['data'])
get_url['url']
await ctx.channel.send(get_url['url'])
except ApiException as e:
await ctx.channel.send("Exception when calling DefaultApi->gifs_search_get: %s\n" % e)
if api_key:
try:
api_response = api_instance.gifs_search_get(api_key, query, lang=lang, limit=15)
api_response.to_dict()['data'][0]
get_url = random.choice(api_response.to_dict()['data'])
get_url['url']
await ctx.channel.send(get_url['url'])
except ApiException as 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.command()
@ -526,7 +535,15 @@ def get_word(word_type):
def main():
logger.info("Initialisation de Kabot")
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
if "test" in argv[-1]: