diff --git a/README.md b/README.md index db3d1bd..07717db 100644 --- a/README.md +++ b/README.md @@ -67,4 +67,15 @@ - [ ] ci setos - [ ] ci setcountry - [ ] ci online_edit `renamed`, cause : `website down` - - [ ] ci list \ No newline at end of file + - [ ] ci list + + --- + + # Cogs.utility commands + - [ ] clock + - [ ] clock * + - [ ] ytdiscover + - [x] iplocalise + - [ ] getheaders + - [ ] git + - [ ] quote \ No newline at end of file diff --git a/bot.py b/bot.py index c32d404..120e46c 100755 --- a/bot.py +++ b/bot.py @@ -24,6 +24,7 @@ log = logging.getLogger(__name__) l_extensions = ( 'cogs.admin', 'cogs.basics', + 'cogs.utility', 'cogs.logs', 'jishaku', ) diff --git a/cogs/basics.py b/cogs/basics.py index d293f46..3f43f06 100644 --- a/cogs/basics.py +++ b/cogs/basics.py @@ -1,4 +1,5 @@ import os +import pathlib import platform import time @@ -40,9 +41,30 @@ class Basics(commands.Cog): """---------------------------------------------------------------------""" + @staticmethod + def fetch_info(): + total = 0 + file_amount = 0 + ENV = "env" + + for path, _, files in os.walk("."): + for name in files: + file_dir = str(pathlib.PurePath(path, name)) + if not name.endswith(".py") or ENV in file_dir: + continue + file_amount += 1 + with open(file_dir, "r", encoding="utf-8") as file: + for line in file: + if not line.strip().startswith("#") or not line.strip(): + total += 1 + + return total, file_amount + @commands.command(name='info', aliases=['about']) async def _info(self, ctx: commands.Context): proc = psutil.Process() + lines, files = self.fetch_info() + with proc.oneshot(): mem = proc.memory_full_info() e = discord.Embed( @@ -93,7 +115,18 @@ class Basics(commands.Cog): ) e.add_field( - name=f"__{Texts('basics').get('Links')}__", + name=f"__:file_folder: {Texts('basics').get('Files')}__", + value=str(files), + inline=True + ) + e.add_field( + name=f"__¶ {Texts('basics').get('Lines')}__", + value=str(lines), + inline=True + ) + + e.add_field( + name=f"__:link: {Texts('basics').get('Links')}__", value="[tuxbot.gnous.eu](https://tuxbot.gnous.eu/) " "| [gnous.eu](https://gnous.eu/) " f"| [{Texts('basics').get('Invite')}](https://discordapp.com/oauth2/authorize?client_id=301062143942590465&scope=bot&permissions=268749888)", diff --git a/cogs/utility.py b/cogs/utility.py new file mode 100644 index 0000000..13a0ecd --- /dev/null +++ b/cogs/utility.py @@ -0,0 +1,78 @@ +import re + +import discord +from discord.ext import commands +from bot import TuxBot +import socket + +from .utils.lang import Texts + + +class Utility(commands.Cog): + + def __init__(self, bot: TuxBot): + self.bot = bot + + """---------------------------------------------------------------------""" + + async def fetch_api(self, ctx: commands.Context, ip, addr): + async with self.bot.session.get(f"http://ip-api.com/json/{ip}") as s: + response: dict = await s.json() + + if response.get('status') == 'success': + e = discord.Embed( + title=f"{Texts('utility').get('Information for')} " + f"``{addr}`` *`({response.get('query')})`*", + color=0x5858d7 + ) + + e.add_field( + name=Texts('utility').get('Belongs to :'), + value=response.get('org', 'N/A'), + inline=False + ) + + e.add_field( + name=Texts('utility').get('Is located at :'), + value=response.get('city', 'N/A'), + inline=True + ) + + e.add_field( + name="Region :", + value=f"{response.get('regionName', 'N/A')} " + f"({response.get('country', 'N/A')})", + inline=True + ) + + e.set_thumbnail( + url=f"https://www.countryflags.io/" + f"{response.get('countryCode')}/flat/64.png") + + await ctx.send(embed=e) + else: + await ctx.send( + content=f"{Texts('utility').get('info not available')}" + f"``{response.get('query')}``") + + @commands.command(name='iplocalise') + async def _iplocalise(self, ctx: commands.Context, addr, ip_type=''): + addr = re.sub(r'http(s?)://', '', addr) + addr = addr[:-1] if addr.endswith('/') else addr + + await ctx.trigger_typing() + + if ip_type in ('v6', 'ipv6'): + try: + ip = socket.getaddrinfo(addr, None, socket.AF_INET6)[1][4][0] + except socket.gaierror: + return await ctx.send( + Texts('utility').get('ipv6 not available')) + else: + ip = socket.gethostbyname(addr) + + await self.fetch_api(ctx, ip, addr) + + +def setup(bot: TuxBot): + bot.add_cog(Utility(bot)) diff --git a/cogs/utils/__init__.py b/cogs/utils/__init__.py index e69de29..caaa513 100755 --- a/cogs/utils/__init__.py +++ b/cogs/utils/__init__.py @@ -0,0 +1,5 @@ +from .checks import * +from .config import * +from .db import * +from .lang import * +from .version import * \ No newline at end of file diff --git a/extras/locales/en/LC_MESSAGES/basics.po b/extras/locales/en/LC_MESSAGES/basics.po index 194ccd3..89d6c26 100644 --- a/extras/locales/en/LC_MESSAGES/basics.po +++ b/extras/locales/en/LC_MESSAGES/basics.po @@ -42,6 +42,12 @@ msgstr "" msgid "Links" msgstr "" +msgid "Files" +msgstr "" + +msgid "Lines" +msgstr "" + msgid "Invite" msgstr "" diff --git a/extras/locales/en/LC_MESSAGES/utility.mo b/extras/locales/en/LC_MESSAGES/utility.mo new file mode 100644 index 0000000..5afe261 Binary files /dev/null and b/extras/locales/en/LC_MESSAGES/utility.mo differ diff --git a/extras/locales/en/LC_MESSAGES/utility.po b/extras/locales/en/LC_MESSAGES/utility.po new file mode 100644 index 0000000..d72dedf --- /dev/null +++ b/extras/locales/en/LC_MESSAGES/utility.po @@ -0,0 +1,31 @@ +# 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 "ipv6 not available" +msgstr "Error, this address is not available in IPv6." + +msgid "Information for" +msgstr "" + +msgid "Belongs to :" +msgstr "" + +msgid "Is located at :" +msgstr "" + +msgid "info not available" +msgstr "" \ No newline at end of file diff --git a/extras/locales/fr/LC_MESSAGES/basics.mo b/extras/locales/fr/LC_MESSAGES/basics.mo index 23ac26e..f594e3b 100644 Binary files a/extras/locales/fr/LC_MESSAGES/basics.mo and b/extras/locales/fr/LC_MESSAGES/basics.mo differ diff --git a/extras/locales/fr/LC_MESSAGES/basics.po b/extras/locales/fr/LC_MESSAGES/basics.po index a345d05..429badb 100644 --- a/extras/locales/fr/LC_MESSAGES/basics.po +++ b/extras/locales/fr/LC_MESSAGES/basics.po @@ -42,6 +42,12 @@ msgstr "Nombre de membres" msgid "Links" msgstr "Liens" +msgid "Files" +msgstr "Fichiers" + +msgid "Lines" +msgstr "Lignes" + msgid "Invite" msgstr "Invitation" diff --git a/extras/locales/fr/LC_MESSAGES/utility.mo b/extras/locales/fr/LC_MESSAGES/utility.mo new file mode 100644 index 0000000..f5d6167 Binary files /dev/null and b/extras/locales/fr/LC_MESSAGES/utility.mo differ diff --git a/extras/locales/fr/LC_MESSAGES/utility.po b/extras/locales/fr/LC_MESSAGES/utility.po new file mode 100644 index 0000000..3e740fb --- /dev/null +++ b/extras/locales/fr/LC_MESSAGES/utility.po @@ -0,0 +1,31 @@ +# 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 "ipv6 not available" +msgstr "Erreur, cette adresse n'est pas disponible en IPv6." + +msgid "Information for" +msgstr "Informations pour" + +msgid "Belongs to :" +msgstr "Appartient à :" + +msgid "Is located at :" +msgstr "Se situe à :" + +msgid "info not available" +msgstr "Erreur, impossible d'obtenir des informations sur cette adresse IP" \ No newline at end of file