2019-09-15 02:31:31 +02:00
|
|
|
|
import os
|
2019-09-22 01:55:43 +02:00
|
|
|
|
import pathlib
|
2019-09-15 01:25:32 +02:00
|
|
|
|
import platform
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
import discord
|
|
|
|
|
import humanize
|
|
|
|
|
import psutil
|
|
|
|
|
from discord.ext import commands
|
|
|
|
|
|
|
|
|
|
from bot import TuxBot
|
|
|
|
|
from .utils.lang import Texts
|
2019-10-06 23:49:00 +02:00
|
|
|
|
from tcp_latency import measure_latency
|
2019-09-15 01:25:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Basics(commands.Cog):
|
|
|
|
|
|
|
|
|
|
def __init__(self, bot: TuxBot):
|
|
|
|
|
self.bot = bot
|
|
|
|
|
|
2019-09-15 02:31:31 +02:00
|
|
|
|
@staticmethod
|
|
|
|
|
def _latest_commits():
|
|
|
|
|
cmd = 'git log -n 3 -s --format="[\`%h\`](https://git.gnous.eu/gnouseu/tuxbot-bot/commits/%H) %s (%cr)"'
|
|
|
|
|
|
|
|
|
|
return os.popen(cmd).read().strip()
|
|
|
|
|
|
2019-09-15 01:25:32 +02:00
|
|
|
|
"""---------------------------------------------------------------------"""
|
|
|
|
|
|
|
|
|
|
@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)
|
2019-10-06 23:49:00 +02:00
|
|
|
|
discordapp = measure_latency(host='google.com', wait=0)[0]
|
2019-09-15 01:25:32 +02:00
|
|
|
|
|
|
|
|
|
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')
|
2019-10-06 23:49:00 +02:00
|
|
|
|
e.add_field(name='discordapp.com', value=f'{discordapp}ms')
|
2019-09-15 01:25:32 +02:00
|
|
|
|
await ctx.send(embed=e)
|
|
|
|
|
|
|
|
|
|
"""---------------------------------------------------------------------"""
|
|
|
|
|
|
2019-09-22 01:55:43 +02:00
|
|
|
|
@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:
|
2019-10-06 01:49:30 +02:00
|
|
|
|
if not line.strip().startswith("#") \
|
|
|
|
|
or not line.strip():
|
2019-09-22 01:55:43 +02:00
|
|
|
|
total += 1
|
|
|
|
|
|
|
|
|
|
return total, file_amount
|
|
|
|
|
|
2019-09-15 02:31:31 +02:00
|
|
|
|
@commands.command(name='info', aliases=['about'])
|
2019-09-15 01:25:32 +02:00
|
|
|
|
async def _info(self, ctx: commands.Context):
|
|
|
|
|
proc = psutil.Process()
|
2019-09-22 01:55:43 +02:00
|
|
|
|
lines, files = self.fetch_info()
|
|
|
|
|
|
2019-09-15 01:25:32 +02:00
|
|
|
|
with proc.oneshot():
|
|
|
|
|
mem = proc.memory_full_info()
|
|
|
|
|
e = discord.Embed(
|
2019-10-06 01:49:30 +02:00
|
|
|
|
title=Texts('basics', ctx).get('Information about TuxBot'),
|
2019-09-15 01:25:32 +02:00
|
|
|
|
color=0x89C4F9)
|
2019-09-15 02:31:31 +02:00
|
|
|
|
|
|
|
|
|
e.add_field(
|
2019-09-29 23:01:49 +02:00
|
|
|
|
name=f"__{Texts('basics', ctx).get('Latest changes')}__",
|
2019-09-15 02:31:31 +02:00
|
|
|
|
value=self._latest_commits(),
|
|
|
|
|
inline=False)
|
|
|
|
|
|
2019-09-15 01:25:32 +02:00
|
|
|
|
e.add_field(
|
|
|
|
|
name=f"__:busts_in_silhouette: "
|
2019-09-29 23:01:49 +02:00
|
|
|
|
f"{Texts('basics', ctx).get('Development')}__",
|
2019-09-15 01:25:32 +02:00
|
|
|
|
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)}** "
|
2019-09-29 23:01:49 +02:00
|
|
|
|
f"{Texts('basics', ctx).get('physical memory')}\n"
|
2019-09-15 01:25:32 +02:00
|
|
|
|
f"**{humanize.naturalsize(mem.vms)}** "
|
2019-09-29 23:01:49 +02:00
|
|
|
|
f"{Texts('basics', ctx).get('virtual memory')}\n",
|
2019-09-15 01:25:32 +02:00
|
|
|
|
inline=True
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
e.add_field(
|
2019-09-29 23:01:49 +02:00
|
|
|
|
name=f"__{Texts('basics', ctx).get('Servers count')}__",
|
2019-09-15 01:25:32 +02:00
|
|
|
|
value=str(len(self.bot.guilds)),
|
|
|
|
|
inline=True
|
|
|
|
|
)
|
|
|
|
|
e.add_field(
|
2019-09-29 23:01:49 +02:00
|
|
|
|
name=f"__{Texts('basics', ctx).get('Channels count')}__",
|
2019-09-15 01:25:32 +02:00
|
|
|
|
value=str(len([_ for _ in self.bot.get_all_channels()])),
|
|
|
|
|
inline=True
|
|
|
|
|
)
|
|
|
|
|
e.add_field(
|
2019-09-29 23:01:49 +02:00
|
|
|
|
name=f"__{Texts('basics', ctx).get('Members count')}__",
|
2019-09-15 01:25:32 +02:00
|
|
|
|
value=str(len([_ for _ in self.bot.get_all_members()])),
|
|
|
|
|
inline=True
|
|
|
|
|
)
|
|
|
|
|
|
2019-09-15 02:31:31 +02:00
|
|
|
|
e.add_field(
|
2019-09-29 23:01:49 +02:00
|
|
|
|
name=f"__:file_folder: {Texts('basics', ctx).get('Files')}__",
|
2019-09-22 01:55:43 +02:00
|
|
|
|
value=str(files),
|
|
|
|
|
inline=True
|
|
|
|
|
)
|
|
|
|
|
e.add_field(
|
2019-09-29 23:01:49 +02:00
|
|
|
|
name=f"__¶ {Texts('basics', ctx).get('Lines')}__",
|
2019-09-22 01:55:43 +02:00
|
|
|
|
value=str(lines),
|
|
|
|
|
inline=True
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
e.add_field(
|
2019-09-29 23:01:49 +02:00
|
|
|
|
name=f"__:link: {Texts('basics', ctx).get('Links')}__",
|
2019-09-15 02:31:31 +02:00
|
|
|
|
value="[tuxbot.gnous.eu](https://tuxbot.gnous.eu/) "
|
|
|
|
|
"| [gnous.eu](https://gnous.eu/) "
|
2019-10-06 01:49:30 +02:00
|
|
|
|
f"| [{Texts('basics', ctx).get('Invite')}](https://discordapp.com/oauth2/authorize?client_id=301062143942590465&scope=bot&permissions=268749888)",
|
2019-09-15 02:31:31 +02:00
|
|
|
|
inline=False
|
|
|
|
|
)
|
|
|
|
|
|
2019-09-15 01:25:32 +02:00
|
|
|
|
e.set_footer(text=f'version: {self.bot.version}')
|
|
|
|
|
|
|
|
|
|
await ctx.send(embed=e)
|
|
|
|
|
|
2019-09-15 02:31:31 +02:00
|
|
|
|
"""---------------------------------------------------------------------"""
|
|
|
|
|
|
2019-09-28 00:57:39 +02:00
|
|
|
|
@commands.command(name='credits', aliases=['contributors', 'authors'])
|
2019-09-15 02:31:31 +02:00
|
|
|
|
async def _credits(self, ctx: commands.Context):
|
|
|
|
|
e = discord.Embed(
|
2019-09-29 23:01:49 +02:00
|
|
|
|
title=Texts('basics', ctx).get('Contributors'),
|
2019-09-15 02:56:41 +02:00
|
|
|
|
color=0x36393f
|
2019-09-15 02:31:31 +02:00
|
|
|
|
)
|
|
|
|
|
|
2019-09-15 02:56:41 +02:00
|
|
|
|
e.add_field(
|
|
|
|
|
name="**Outout#4039** ",
|
|
|
|
|
value="• https://git.gnous.eu/mael ⠀\n"
|
|
|
|
|
"• mael@gnous.eu\n"
|
|
|
|
|
"• [@outoutxyz](https://twitter.com/outouxyz)",
|
|
|
|
|
inline=True
|
|
|
|
|
)
|
|
|
|
|
e.add_field(
|
|
|
|
|
name="**Romain#5117** ",
|
|
|
|
|
value="• https://git.gnous.eu/Romain\n"
|
|
|
|
|
"• romain@gnous.eu",
|
|
|
|
|
inline=True
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
await ctx.send(embed=e)
|
|
|
|
|
|
2019-09-15 01:25:32 +02:00
|
|
|
|
|
|
|
|
|
def setup(bot: TuxBot):
|
|
|
|
|
bot.add_cog(Basics(bot))
|