LBI/modules/git.py

38 lines
1.4 KiB
Python
Raw Permalink Normal View History

import os
2019-03-02 14:38:37 +01:00
2019-03-02 22:05:15 +01:00
class MainClass:
def __init__(self, client, modules, owners, prefix):
self.client = client
self.modules = modules
self.owners = owners
self.prefix = prefix
2019-03-02 14:38:37 +01:00
self.events = ['on_message'] # events list
self.command = "%sgit" % self.prefix # command prefix (can be empty to catch every single messages)
2019-03-02 14:38:37 +01:00
self.name = "Git"
self.description = "Module de gestion de Git"
self.interactive = True
self.authlist = []
self.color = 0xdc0000
self.help = """\
</prefix>git update
=> Execute les commandes suivantes dans le dossier du bot:
```BASH
git fetch --all
git reset --hard origin/<branch_name>```
"""
2019-03-02 14:38:37 +01:00
async def on_message(self, message):
2019-03-02 14:38:37 +01:00
args = message.content.split(' ')
if len(args) == 2 and args[1] == 'update':
2019-03-02 22:05:15 +01:00
with os.popen('git fetch --all') as std_out:
await message.channel.send(std_out.read())
with os.popen('git symbolic-ref HEAD 2>/dev/null') as std_out:
branch = std_out.read().replace('refs/heads/', '')
with os.popen('git reset --hard origin/%s' % branch) as std_out:
await message.channel.send(std_out.read())
2019-03-02 14:38:37 +01:00
await message.channel.send(message.author.mention + ", Le dépôt a été mis à jour (fetch + reset --hard).")
else:
await self.modules['help'][1].send_help(message.channel, self)