From 289fedb4b7ee195831ae6933387d5e9c643b814c Mon Sep 17 00:00:00 2001 From: Romain J Date: Sun, 15 Sep 2019 01:25:32 +0200 Subject: [PATCH] refactor(command|basics): rewrite info and ping commands --- README.md | 12 ++++- bot.py | 1 + cogs/basics.py | 88 +++++++++++++++++++++++++++++++ cogs/utils/version.py | 2 +- launcher.py | 1 - locales/en/LC_MESSAGES/basics.mo | Bin 0 -> 363 bytes locales/en/LC_MESSAGES/basics.po | 37 +++++++++++++ locales/fr/LC_MESSAGES/basics.mo | Bin 0 -> 717 bytes locales/fr/LC_MESSAGES/basics.po | 37 +++++++++++++ requirements.txt | 5 +- 10 files changed, 178 insertions(+), 5 deletions(-) create mode 100644 cogs/basics.py create mode 100644 locales/en/LC_MESSAGES/basics.mo create mode 100644 locales/en/LC_MESSAGES/basics.po create mode 100644 locales/fr/LC_MESSAGES/basics.mo create mode 100644 locales/fr/LC_MESSAGES/basics.po diff --git a/README.md b/README.md index dee359e..0be4848 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ - [ ] Send email or Telegram's message when something is wrong on the bot - [ ] Create skynet (group of multiple commands about sky (planes, meteo,...)) - - --- + + ------- # Cogs.admin commands @@ -45,4 +45,12 @@ - [x] delete - [x] deletefrom `removed`, now `delete (from|to|in)` - [x] embed `removed`, cause : `never used` + + --- + + # Cogs.basics commands + - [x] ping + - [x] info + - [ ] help + - [ ] credits `new command` \ No newline at end of file diff --git a/bot.py b/bot.py index b5fb74d..adc6fdc 100755 --- a/bot.py +++ b/bot.py @@ -23,6 +23,7 @@ log = logging.getLogger(__name__) l_extensions = ( 'cogs.admin', + 'cogs.basics', 'jishaku', ) diff --git a/cogs/basics.py b/cogs/basics.py new file mode 100644 index 0000000..2d56eea --- /dev/null +++ b/cogs/basics.py @@ -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)) diff --git a/cogs/utils/version.py b/cogs/utils/version.py index 37f922c..9aaf3ec 100644 --- a/cogs/utils/version.py +++ b/cogs/utils/version.py @@ -9,4 +9,4 @@ class Version: def __str__(self) -> str: 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}' diff --git a/launcher.py b/launcher.py index b425a74..8712926 100644 --- a/launcher.py +++ b/launcher.py @@ -5,7 +5,6 @@ import socket import sys import click -import git import requests from bot import TuxBot diff --git a/locales/en/LC_MESSAGES/basics.mo b/locales/en/LC_MESSAGES/basics.mo new file mode 100644 index 0000000000000000000000000000000000000000..e56e9c9c4f698196d1c9f23390bf6da85a3ddd45 GIT binary patch literal 363 zcmYjM!A`?43>^}u9yxQ!f!lCNCy=(VO$%!_D$;i9x=C;gn<+&jt0ZI9WJ`&UtGF+;z;ObD^tDU&O)?@Et;mRG$SiMf8a|&wjx_c zY2vNY9OedK>b)OC>bwbGSv+TC~=^h2oAWk9Vf%Ec2sx^EMkG&`o6g%<%Gsgx zD^pCpIEuy5ec)4XUTKTk-DqoP*5a4Fst>Bvw`BLKOoMi^$rms@>N+nkXh7&)wJ&wS f$nd$e-V!w$_wXL>T1M)&K-(?z>y`xmjo14HFE3?c literal 0 HcmV?d00001 diff --git a/locales/en/LC_MESSAGES/basics.po b/locales/en/LC_MESSAGES/basics.po new file mode 100644 index 0000000..ebf8a66 --- /dev/null +++ b/locales/en/LC_MESSAGES/basics.po @@ -0,0 +1,37 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR ORGANIZATION +# FIRST AUTHOR , 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 \n" +"Language-Team: LANGUAGE \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 "" \ No newline at end of file diff --git a/locales/fr/LC_MESSAGES/basics.mo b/locales/fr/LC_MESSAGES/basics.mo new file mode 100644 index 0000000000000000000000000000000000000000..8a09184b02ff9d836974f908c96d8803c723c2d3 GIT binary patch literal 717 zcmZ9JPj1sd6vhX{0vQUT8(6TIeKo_;r;>g8M%ji zMV=tvkPYO=T7RKFM1CVp{~u)U79sbMN4S4|```Hq>SL@wpf=|pQ8!U9*7cWl{T-F` z7hDL)N;;F3(8PfyWU|Ns_ntVFD(5xnCL#ass`4rUkl`*JgTNR7COlLf! zIpk8+WSJ^mwdGLB_b}7Uo3mrQgw_@v+Wj~7z@^9TXzWFyF^po?SFn09bGQbJZkyd5 zX5!PM-5tw(zGZHkCN{DWEYrqi-S^hDM=Xe#W7AiW6?j|kqR=&bUTPLAF3OB+sVsUl z@qHTFflGJY!1nwD+i^zjc)X9TBB^)+EC!xi)VIUIq?v8k_YbnPBUQ3*1YY2_(|0?j z(U(HwA7gP{;IJCb^|K=5sd!0e3$9Agdz1Kx_1eB>mQzs76*DX#;jA+wA*=MkWl7R1#}LLZxb7Ft}a)B74Uy#B`qs;omhJjV?m4ZhE>_* aSE-WZSC_d=(SMcUSq1IMDn-aLAb$a^Kg+@Z literal 0 HcmV?d00001 diff --git a/locales/fr/LC_MESSAGES/basics.po b/locales/fr/LC_MESSAGES/basics.po new file mode 100644 index 0000000..fd644d0 --- /dev/null +++ b/locales/fr/LC_MESSAGES/basics.po @@ -0,0 +1,37 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR ORGANIZATION +# FIRST AUTHOR , 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 \n" +"Language-Team: LANGUAGE \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" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index eff90f1..789361e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,9 @@ +humanize discord.py[voice] jishaku lxml click asyncpg>=0.12.0 -gitpython \ No newline at end of file +gitpython +requests +psutil \ No newline at end of file