refactor(command|basics): rewrite info and ping commands

This commit is contained in:
Romain J 2019-09-15 01:25:32 +02:00
parent a9a8572aad
commit 289fedb4b7
10 changed files with 178 additions and 5 deletions

View file

@ -29,7 +29,7 @@
- [ ] Send email or Telegram's message when something is wrong on the bot - [ ] Send email or Telegram's message when something is wrong on the bot
- [ ] Create skynet (group of multiple commands about sky (planes, meteo,...)) - [ ] Create skynet (group of multiple commands about sky (planes, meteo,...))
--- -------
# Cogs.admin commands # Cogs.admin commands
@ -46,3 +46,11 @@
- [x] deletefrom `removed`, now `delete (from|to|in)` - [x] deletefrom `removed`, now `delete (from|to|in)`
- [x] embed `removed`, cause : `never used` - [x] embed `removed`, cause : `never used`
---
# Cogs.basics commands
- [x] ping
- [x] info
- [ ] help
- [ ] credits `new command`

1
bot.py
View file

@ -23,6 +23,7 @@ log = logging.getLogger(__name__)
l_extensions = ( l_extensions = (
'cogs.admin', 'cogs.admin',
'cogs.basics',
'jishaku', 'jishaku',
) )

88
cogs/basics.py Normal file
View file

@ -0,0 +1,88 @@
import platform
import time
import discord
import humanize
import psutil
from discord.ext import commands
from bot import TuxBot
from .utils.lang import Texts
class Basics(commands.Cog):
def __init__(self, bot: TuxBot):
self.bot = bot
"""---------------------------------------------------------------------"""
@commands.command(name='ping')
async def _ping(self, ctx: commands.Context):
start = time.perf_counter()
await ctx.trigger_typing()
end = time.perf_counter()
latency = round(self.bot.latency * 1000, 2)
typing = round((end - start) * 1000, 2)
e = discord.Embed(title='Ping', color=discord.Color.teal())
e.add_field(name='Websocket', value=f'{latency}ms')
e.add_field(name='Typing', value=f'{typing}ms')
await ctx.send(embed=e)
"""---------------------------------------------------------------------"""
@commands.command(name='info')
async def _info(self, ctx: commands.Context):
proc = psutil.Process()
with proc.oneshot():
mem = proc.memory_full_info()
e = discord.Embed(
title=f"{Texts('basics').get('Information about TuxBot')}",
color=0x89C4F9)
e.add_field(
name=f"__:busts_in_silhouette: "
f"{Texts('basics').get('Development')}__",
value=f"**Romain#5117:** [git](https://git.gnous.eu/Romain)\n"
f"**Outout#4039:** [git](https://git.gnous.eu/mael)\n",
inline=True
)
e.add_field(
name="__<:python:596577462335307777> Python__",
value=f"**python** `{platform.python_version()}`\n"
f"**discord.py** `{discord.__version__}`",
inline=True
)
e.add_field(
name="__:gear: Usage__",
value=f"**{humanize.naturalsize(mem.rss)}** "
f"{Texts('basics').get('physical memory')}\n"
f"**{humanize.naturalsize(mem.vms)}** "
f"{Texts('basics').get('virtual memory')}\n",
inline=True
)
e.add_field(
name=f"__{Texts('basics').get('Servers count')}__",
value=str(len(self.bot.guilds)),
inline=True
)
e.add_field(
name=f"__{Texts('basics').get('Channels count')}__",
value=str(len([_ for _ in self.bot.get_all_channels()])),
inline=True
)
e.add_field(
name=f"__{Texts('basics').get('Members count')}__",
value=str(len([_ for _ in self.bot.get_all_members()])),
inline=True
)
e.set_footer(text=f'version: {self.bot.version}')
await ctx.send(embed=e)
def setup(bot: TuxBot):
bot.add_cog(Basics(bot))

View file

@ -9,4 +9,4 @@ class Version:
def __str__(self) -> str: def __str__(self) -> str:
build = self.build[:10] build = self.build[:10]
return f'v{self.major}.{self.minor}.{self.patch}{self.pre_release}-{build}' return f'v{self.major}.{self.minor}.{self.patch}{self.pre_release}+{build}'

View file

@ -5,7 +5,6 @@ import socket
import sys import sys
import click import click
import git
import requests import requests
from bot import TuxBot from bot import TuxBot

Binary file not shown.

View file

@ -0,0 +1,37 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2019-09-08 19:04+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"
msgid "Information about TuxBot"
msgstr ""
msgid "Development"
msgstr ""
msgid "physical memory"
msgstr ""
msgid "virtual memory"
msgstr ""
msgid "Servers count"
msgstr ""
msgid "Channels count"
msgstr ""
msgid "Members count"
msgstr ""

Binary file not shown.

View file

@ -0,0 +1,37 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2019-09-08 19:04+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"
msgid "Information about TuxBot"
msgstr "Informations sur TuxBot"
msgid "Development"
msgstr "Développement"
msgid "physical memory"
msgstr "mémoire physique"
msgid "virtual memory"
msgstr "mémoire virtuelle"
msgid "Servers count"
msgstr "Nombre de serveurs"
msgid "Channels count"
msgstr "Nombre de channel"
msgid "Members count"
msgstr "Nombre de membres"

View file

@ -1,6 +1,9 @@
humanize
discord.py[voice] discord.py[voice]
jishaku jishaku
lxml lxml
click click
asyncpg>=0.12.0 asyncpg>=0.12.0
gitpython gitpython
requests
psutil