add(command|warn): start dev of command warn
This commit is contained in:
parent
764068ef22
commit
9274895226
8 changed files with 80 additions and 1086 deletions
15
README.md
15
README.md
|
@ -54,4 +54,17 @@
|
||||||
- [x] info
|
- [x] info
|
||||||
- [ ] help
|
- [ ] help
|
||||||
- [x] credits `new command`
|
- [x] credits `new command`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# Cogs.ci commands
|
||||||
|
- [ ] ci (help?)
|
||||||
|
- [ ] ci show
|
||||||
|
- [ ] ci register
|
||||||
|
- [ ] ci delete
|
||||||
|
- [ ] ci update
|
||||||
|
- [ ] ci setconfig
|
||||||
|
- [ ] ci setos
|
||||||
|
- [ ] ci setcountry
|
||||||
|
- [ ] ci online_edit `renamed`, cause : `website down`
|
||||||
|
- [ ] ci list
|
6
bot.py
6
bot.py
|
@ -5,6 +5,7 @@ import traceback
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
import asyncpg
|
||||||
import discord
|
import discord
|
||||||
import git
|
import git
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
@ -37,9 +38,9 @@ async def _prefix_callable(bot, message: discord.message) -> list:
|
||||||
|
|
||||||
|
|
||||||
class TuxBot(commands.AutoShardedBot):
|
class TuxBot(commands.AutoShardedBot):
|
||||||
__slots__ = ('uptime', 'config', 'session')
|
__slots__ = ('uptime', 'config', 'db', 'session')
|
||||||
|
|
||||||
def __init__(self, unload: list):
|
def __init__(self, unload: list, db: asyncpg.pool.Pool):
|
||||||
super().__init__(command_prefix=_prefix_callable, pm_help=None,
|
super().__init__(command_prefix=_prefix_callable, pm_help=None,
|
||||||
help_command=None, description=description,
|
help_command=None, description=description,
|
||||||
help_attrs=dict(hidden=True),
|
help_attrs=dict(hidden=True),
|
||||||
|
@ -47,6 +48,7 @@ class TuxBot(commands.AutoShardedBot):
|
||||||
|
|
||||||
self.uptime: datetime = datetime.datetime.utcnow()
|
self.uptime: datetime = datetime.datetime.utcnow()
|
||||||
self.config = config
|
self.config = config
|
||||||
|
self.db = db
|
||||||
self._prev_events = deque(maxlen=10)
|
self._prev_events = deque(maxlen=10)
|
||||||
self.session = aiohttp.ClientSession(loop=self.loop)
|
self.session = aiohttp.ClientSession(loop=self.loop)
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ from typing import Union
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
import humanize
|
||||||
|
|
||||||
from bot import TuxBot
|
from bot import TuxBot
|
||||||
from .utils.lang import Texts
|
from .utils.lang import Texts
|
||||||
|
@ -12,8 +13,9 @@ class Admin(commands.Cog):
|
||||||
|
|
||||||
def __init__(self, bot: TuxBot):
|
def __init__(self, bot: TuxBot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
self.db = bot.db
|
||||||
|
|
||||||
async def cog_check(self, ctx: commands.Context):
|
async def cog_check(self, ctx: commands.Context) -> bool:
|
||||||
permissions: discord.Permissions = ctx.channel.permissions_for(
|
permissions: discord.Permissions = ctx.channel.permissions_for(
|
||||||
ctx.author)
|
ctx.author)
|
||||||
|
|
||||||
|
@ -217,6 +219,49 @@ class Admin(commands.Cog):
|
||||||
await ctx.send(Texts('utils').get("Unable to find the message"),
|
await ctx.send(Texts('utils').get("Unable to find the message"),
|
||||||
delete_after=5)
|
delete_after=5)
|
||||||
|
|
||||||
|
"""---------------------------------------------------------------------"""
|
||||||
|
|
||||||
|
@commands.group(name='warn', aliases=['warns'])
|
||||||
|
async def _warn(self, ctx: commands.Context):
|
||||||
|
if ctx.invoked_subcommand is None:
|
||||||
|
query = """
|
||||||
|
SELECT user_id, reason, created_at FROM warns
|
||||||
|
WHERE created_at >= $1 AND server_id = $2
|
||||||
|
ORDER BY created_at
|
||||||
|
DESC LIMIT 10
|
||||||
|
"""
|
||||||
|
week_ago = datetime.datetime.now() - datetime.timedelta(weeks=6)
|
||||||
|
|
||||||
|
async with self.bot.db.acquire() as con:
|
||||||
|
warns = await con.fetch(query, week_ago, ctx.guild.id)
|
||||||
|
warns_list = ''
|
||||||
|
|
||||||
|
for warn in warns:
|
||||||
|
user_id = warn.get('user_id')
|
||||||
|
user = await self.bot.fetch_user(user_id)
|
||||||
|
reason = warn.get('reason')
|
||||||
|
ago = humanize.naturaldelta(
|
||||||
|
datetime.datetime.now() - warn.get('created_at')
|
||||||
|
)
|
||||||
|
|
||||||
|
warns_list += f"**{user}**: `{reason}` *({ago} ago)*\n"
|
||||||
|
|
||||||
|
e = discord.Embed(
|
||||||
|
title=f"{len(warns)} {Texts('admin').get('last warns')}: ",
|
||||||
|
description=warns_list
|
||||||
|
)
|
||||||
|
|
||||||
|
await ctx.send(embed=e)
|
||||||
|
|
||||||
|
@_warn.command(name='add', aliases=['new'])
|
||||||
|
async def _warn_new(self, ctx: commands.Context, member: discord.Member,
|
||||||
|
*, reason):
|
||||||
|
"""
|
||||||
|
todo: push in database
|
||||||
|
if warn > 2 for member:
|
||||||
|
todo: ask for confirmation to kick or ban
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def setup(bot: TuxBot):
|
def setup(bot: TuxBot):
|
||||||
bot.add_cog(Admin(bot))
|
bot.add_cog(Admin(bot))
|
||||||
|
|
1081
cogs/utils/db.py
1081
cogs/utils/db.py
File diff suppressed because it is too large
Load diff
|
@ -22,4 +22,7 @@ msgid "Unable to ban this user"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
msgid "Unable to kick this user"
|
msgid "Unable to kick this user"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "last warns"
|
||||||
msgstr ""
|
msgstr ""
|
Binary file not shown.
|
@ -22,4 +22,7 @@ msgid "Unable to ban this user"
|
||||||
msgstr "Impossible de bannir cet utilisateur"
|
msgstr "Impossible de bannir cet utilisateur"
|
||||||
|
|
||||||
msgid "Unable to kick this user"
|
msgid "Unable to kick this user"
|
||||||
msgstr "Impossible d'expulser cet utilisateur"
|
msgstr "Impossible d'expulser cet utilisateur"
|
||||||
|
|
||||||
|
msgid "last warns"
|
||||||
|
msgstr "derniers avertissements"
|
|
@ -4,7 +4,9 @@ import logging
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import asyncpg
|
||||||
import click
|
import click
|
||||||
|
import git
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from bot import TuxBot
|
from bot import TuxBot
|
||||||
|
@ -50,17 +52,16 @@ def run_bot(unload: list = []):
|
||||||
print(Texts().get('Starting...'))
|
print(Texts().get('Starting...'))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pool = loop.run_until_complete(
|
db = loop.run_until_complete(
|
||||||
Table.create_pool(config.postgresql, command_timeout=60)
|
Table.create_pool(config.postgresql, command_timeout=60)
|
||||||
)
|
)
|
||||||
except socket.gaierror as e:
|
except socket.gaierror:
|
||||||
click.echo(Texts().get("Could not set up PostgreSQL..."),
|
click.echo(Texts().get("Could not set up PostgreSQL..."),
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
log.exception(Texts().get("Could not set up PostgreSQL..."))
|
log.exception(Texts().get("Could not set up PostgreSQL..."))
|
||||||
return
|
return
|
||||||
|
|
||||||
bot = TuxBot(unload)
|
bot = TuxBot(unload, db)
|
||||||
bot.pool = pool
|
|
||||||
bot.run()
|
bot.run()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue