Exemplo n.º 1
0
from os.path import dirname
from typing import TYPE_CHECKING

import discord

from tuxbot.core.i18n import Translator

if TYPE_CHECKING:
    from .view import ViewController

_ = Translator("Network", dirname(dirname(dirname(__file__))))


class Embeds:
    def __init__(self, controller: "ViewController"):
        self.controller = controller

        self.ctx = self.controller.ctx
        self.data = self.controller.data

    # =========================================================================
    # =========================================================================

    async def global_embed(self) -> discord.Embed:
        rir = self.data["ipwhois"].get("asn_registry", "N/A")
        cidr = self.data["ipwhois"].get("asn_cidr", "N/A")

        e = discord.Embed(
            color=0x1E448A,
            title=_(
                "Information for ``{ip} ({ip_address})``",
Exemplo n.º 2
0
from tuxbot.core.utils.functions.levenshtein import levenshtein
from tuxbot.core.utils.console import console
from tuxbot.core.utils import emotes as utils_emotes
from tuxbot.core.config import (
    Config,
    ConfigFile,
    search_for,
)
from tuxbot.core.i18n import Translator
from . import __version__, ExitCodes
from . import exceptions
from .utils.cache import Cache
from .utils.colors import Colors

log = logging.getLogger("tuxbot")
_ = Translator("core", __file__)

packages: Tuple = (
    "jishaku",
    "tuxbot.cogs.Admin",
    "tuxbot.cogs.Logs",
    "tuxbot.cogs.Dev",
    "tuxbot.cogs.Utils",
    "tuxbot.cogs.Polls",
    "tuxbot.cogs.Custom",
    "tuxbot.cogs.Network",
    "tuxbot.cogs.Linux",
    "tuxbot.cogs.Mod",
    "tuxbot.cogs.Tags",
    "tuxbot.cogs.Math",
    "tuxbot.cogs.Test",
Exemplo n.º 3
0
import json
from os.path import dirname

import discord

from tuxbot.core.i18n import Translator
from tuxbot.core.utils.functions.utils import upper_first
from tuxbot.core.utils import emotes as utils_emotes
from .exceptions import InvalidChannel, BadPoll, TooLongProposition
from ..models import Response, Poll, Suggest

_ = Translator("Polls", dirname(__file__))


async def _poll_reaction_add(self, pld: discord.RawReactionActionEvent,
                             poll: Poll):
    if poll.is_anonymous:
        try:
            await self.remove_reaction(pld)
        except discord.errors.Forbidden:
            pass
    choice = utils_emotes.get_index(pld.emoji.name)

    response = await Response.get_or_none(user_id=pld.user_id,
                                          choice=choice,
                                          poll__id=poll.id)

    if response is not None:
        await poll.choices.remove(response)
        await response.delete()
    else:
Exemplo n.º 4
0
import humanize
import psutil
from discord.ext import commands
from tuxbot.cogs.Utils.functions.quote import Quote

from tuxbot import version_info as tuxbot_version_info, __version__

from tuxbot.core.utils.functions.extra import command_extra, ContextPlus
from tuxbot.core.bot import Tux
from tuxbot.core.i18n import Translator
from .functions.converters import QuoteConverter, UserOrMeConverter
from .functions.exceptions import UserNotFound
from .functions.info import fetch_info

log = logging.getLogger("tuxbot.cogs.Utils")
_ = Translator("Utils", __file__)


class Utils(commands.Cog):
    def __init__(self, bot: Tux, version_info):
        self.bot = bot
        self.version_info = version_info

    # =========================================================================

    async def cog_command_error(self, ctx: ContextPlus, error):
        if isinstance(error, UserNotFound):
            await ctx.send(_(str(error), ctx, self.bot.config))

    # =========================================================================
    # =========================================================================
Exemplo n.º 5
0
from tuxbot.core.utils.functions.extra import (
    ContextPlus,
    command_extra,
)

from .config import MathConfig
from .functions.converters import LatexConverter, ExprConverter
from .functions.utils import (
    get_latex_bytes,
    Wolfram,
    clean_query,
    get_graph_bytes,
)

log = logging.getLogger("tuxbot.cogs.Math")
_ = Translator("Math", __file__)


class Math(commands.Cog):
    def __init__(self, bot: Tux, version_info):
        self.bot = bot
        self.version_info = version_info

        self.__config: MathConfig = ConfigFile(
            str(cogs_data_path("Math") / "config.yaml"),
            MathConfig,
        ).config

        self.WA = Wolfram(self.bot.loop, self.__config.WolframAlphaKey)

    async def cog_before_invoke(self, ctx: ContextPlus):
Exemplo n.º 6
0
import discord
from discord.ext import commands
from yarl import URL

from tuxbot.core.utils.functions.extra import ContextPlus, group_extra
from tuxbot.core.utils.functions.utils import upper_first
from tuxbot.core.bot import Tux
from tuxbot.core.i18n import Translator
from tuxbot.core.utils import emotes as utils_emotes
from .functions import listeners
from .functions.converters import NewPropositionConvertor, PollConverter
from .models import Poll
from .models.suggests import Suggest

log = logging.getLogger("tuxbot.cogs.Polls")
_ = Translator("Polls", __file__)


class Polls(commands.Cog):
    def __init__(self, bot: Tux, version_info):
        self.bot = bot
        self.version_info = version_info

    async def cog_command_error(self, ctx, error):
        await listeners.cog_command_error(self, ctx, error)

    @commands.Cog.listener()
    async def on_raw_reaction_add(self, pld: discord.RawReactionActionEvent):
        await listeners.on_raw_reaction_add(self, pld)

    @commands.Cog.listener()
Exemplo n.º 7
0
from tuxbot.core.i18n import (
    Translator,
    find_locale,
    get_locale_name,
    list_locales,
)
from tuxbot.core.utils.functions.extra import (
    group_extra,
    ContextPlus,
)

from .functions.converters import AliasConvertor
from .functions.utils import save_lang, get_aliases, save_alias

log = logging.getLogger("tuxbot.cogs.Custom")
_ = Translator("Custom", __file__)


class Custom(commands.Cog):
    def __init__(self, bot: Tux, version_info):
        self.bot = bot
        self.version_info = version_info

    async def cog_command_error(self, ctx: ContextPlus, error):
        if isinstance(error, commands.BadArgument):
            await ctx.send(_(str(error), ctx, self.bot.config))

    # =========================================================================
    # =========================================================================

    @group_extra(name="custom", aliases=["perso"], deletable=True)
Exemplo n.º 8
0
from discord.ext import commands
from tuxbot.cogs.Dev.functions.HTTPs import HttpCode

from tuxbot.cogs.Dev.functions.exceptions import (
    UnknownHttpCode,
    TioUnknownLang,
)

from tuxbot.cogs.Dev.functions.converters import (
    HttpCodeConverter, )
from tuxbot.core.bot import Tux
from tuxbot.core.i18n import Translator
from tuxbot.core.utils.functions.extra import command_extra, ContextPlus

log = logging.getLogger("tuxbot.cogs.Dev")
_ = Translator("Dev", __file__)


class Dev(commands.Cog):
    def __init__(self, bot: Tux, version_info):
        self.bot = bot
        self.version_info = version_info

    async def cog_command_error(self, ctx: ContextPlus, error):
        if isinstance(error, (UnknownHttpCode, TioUnknownLang)):
            await ctx.send(_(str(error), ctx, self.bot.config))

    # =========================================================================
    # =========================================================================

    @command_extra(name="http", deletable=True)
Exemplo n.º 9
0
from tuxbot.core import Config

from tuxbot.core.utils import checks
from tuxbot.core.bot import Tux
from tuxbot.core.i18n import Translator
from tuxbot.core.utils import emotes as utils_emotes
from tuxbot.core.utils.functions.extra import (
    command_extra,
    ContextPlus,
    group_extra,
)

from .functions.converters import ChannelConverter

log = logging.getLogger("tuxbot.cogs.Admin")
_ = Translator("Admin", __file__)


class Admin(commands.Cog):
    def __init__(self, bot: Tux, version_info):
        self.bot = bot
        self.version_info = version_info

    # =========================================================================
    # =========================================================================

    @command_extra(name="quit", aliases=["shutdown"], deletable=False)
    @checks.is_owner()
    async def _quit(self, ctx: ContextPlus):
        await ctx.send("*quit...*")
        await self.bot.shutdown()
Exemplo n.º 10
0
    InvalidIp,
    VersionNotFound,
    InvalidDomain,
    InvalidQueryType,
    InvalidAsn,
)
from .functions.converters import (
    IPConverter,
    DomainConverter,
    QueryTypeConverter,
    ASConverter,
    InetConverter,
)

log = logging.getLogger("tuxbot.cogs.Network")
_ = Translator("Network", __file__)


class Network(commands.Cog):
    _peeringdb_net: Optional[dict]

    def __init__(self, bot: Tux, version_info):
        self.bot = bot
        self.version_info = version_info

        self.__config: NetworkConfig = ConfigFile(
            str(cogs_data_path("Network") / "config.yaml"),
            NetworkConfig,
        ).config

        self._peeringdb_net = None
Exemplo n.º 11
0
import logging

from discord.ext import commands

from tuxbot.core.bot import Tux
from tuxbot.core.i18n import Translator
from tuxbot.core.utils import checks
from tuxbot.core.utils.functions.extra import command_extra, ContextPlus

log = logging.getLogger("tuxbot.cogs.Test")
_ = Translator("Test", __file__)


class Test(commands.Cog):
    def __init__(self, bot: Tux, version_info):
        self.bot = bot
        self.version_info = version_info

    # =========================================================================
    # =========================================================================

    @command_extra(name="crash", deletable=True)
    @checks.is_owner()
    async def _crash(self, ctx: ContextPlus, crash_type: str):
        if crash_type == "ZeroDivisionError":
            await ctx.send(str(5 / 0))
        elif crash_type == "TypeError":
            # noinspection PyTypeChecker
            await ctx.send(str(int([])))  # type: ignore
        elif crash_type == "IndexError":
            await ctx.send(str([0][5]))
Exemplo n.º 12
0
import logging
from discord.ext import commands
from structured_config import ConfigFile

from tuxbot.core.bot import Tux
from tuxbot.core.i18n import Translator
from tuxbot.core.utils.data_manager import cogs_data_path
from .config import HelpConfig
from .functions.utils import HelpCommand

log = logging.getLogger("tuxbot.cogs.Help")
_ = Translator("Help", __file__)


class Help(commands.Cog):
    def __init__(self, bot: Tux, version_info):
        self.bot = bot
        self.version_info = version_info

        self.__config: HelpConfig = ConfigFile(
            str(cogs_data_path("Help") / "config.yaml"),
            HelpConfig,
        ).config

        self.old_help_command = bot.help_command
        bot.help_command = HelpCommand(self.__config)
        bot.help_command.cog = self

    def cog_unload(self):
        self.bot.help_command = self.old_help_command
Exemplo n.º 13
0
from discord.ext import commands, tasks  # type: ignore
from structured_config import ConfigFile

from tuxbot.core.bot import Tux
from tuxbot.core.i18n import Translator
from tuxbot.core.utils.functions.extra import (
    command_extra,
    ContextPlus,
)
from tuxbot.core.utils.data_manager import cogs_data_path
from .config import LogsConfig
from .functions.utils import sort_by
from ...core.utils.functions.utils import shorten

log = logging.getLogger("tuxbot.cogs.Logs")
_ = Translator("Logs", __file__)


class GatewayHandler(logging.Handler):
    def __init__(self, cog):
        self.cog = cog
        super().__init__(logging.INFO)

    def filter(self, record: LogRecord):
        return (record.name == "discord.gateway" or "Shard ID" in record.msg
                or "Websocket closed " in record.msg)

    def emit(self, record: LogRecord):
        self.cog.add_record(record)

Exemplo n.º 14
0
import logging
from discord.ext import commands

from tuxbot.core.bot import Tux
from tuxbot.core.i18n import Translator

log = logging.getLogger("tuxbot.cogs.Stats")
_ = Translator("Stats", __file__)


class Stats(commands.Cog):
    def __init__(self, bot: Tux, version_info):
        self.bot = bot
        self.version_info = version_info

    # =========================================================================
    # =========================================================================