2019-03-02 14:38:37 +01:00
|
|
|
# dummy module
|
2019-03-01 15:26:14 +01:00
|
|
|
import os
|
2019-03-02 14:38:37 +01:00
|
|
|
|
|
|
|
|
2019-03-01 15:26:14 +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-01 15:26:14 +01:00
|
|
|
|
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 = """\
|
2019-03-01 15:26:14 +01:00
|
|
|
</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
|
|
|
|
2019-03-01 15:26:14 +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-01 15:26:14 +01:00
|
|
|
with os.popen('git fetch --all') as stdin:
|
|
|
|
await message.channel.send(stdin.read())
|
|
|
|
with os.popen('git symbolic-ref HEAD 2>/dev/null') as stdin:
|
2019-03-02 14:38:37 +01:00
|
|
|
branch = stdin.read().replace('refs/heads/', '')
|
|
|
|
with os.popen('git reset --hard origin/%s' % branch) as stdin:
|
2019-03-01 15:26:14 +01:00
|
|
|
await message.channel.send(stdin.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).")
|
2019-03-01 15:26:14 +01:00
|
|
|
else:
|
|
|
|
await self.modules['help'][1].send_help(message.channel, self)
|