def __init__(self, Config: ConfigParser = ConfigParser()): self.Config: ConfigParser = Config self.version: str = self.Config.get("version", "[N/A]") self.start_time: int = time.time( ) # together with another time.time(), used to know how long phaaze is running # get the active/load class, aka, what sould get started self.Active: ActiveStore = ActiveStore(self.Config) # a class filled with permanent vars, mainly from external sources or whatever self.Vars: VarsStore = VarsStore(self.Config) # the key to everything, that will be needed to connect to everything thats not ourself self.Access: AccessStore = AccessStore(self.Config) # contains user limits for all addeble things, like custom command amount self.Limit: LimitStore = LimitStore(self.Config) # log to handler of choice self.Logger: PhaazeLogger = PhaazeLogger() # all featured "superclasses" aka, stuff that makes calls to somewhere # all of these get added by self.Mainframe when started # both the actual working part and a quick link to there running loops, to inject async funtions for them to run # most likly used for the worker, that can calculate time consuming functions or discord because send_message must be called from this loop self.Discord: PhaazebotDiscord = PhaazebotDiscord(self) self.DiscordLoop: asyncio.AbstractEventLoop = None self.Twitch = None self.TwitchLoop: asyncio.AbstractEventLoop = None self.TwitchEvents: PhaazebotTwitchEvents = PhaazebotTwitchEvents(self) self.TwitchEventsLoop: asyncio.AbstractEventLoop = None self.Osu: PhaazebotOsu = PhaazebotOsu(self) self.OsuLoop: asyncio.AbstractEventLoop = None self.Twitter = None self.TwitterLoop: asyncio.AbstractEventLoop = None self.Web: PhaazebotWeb = PhaazebotWeb(self) self.WebLoop: asyncio.AbstractEventLoop = None self.WorkerLoop: asyncio.AbstractEventLoop = None # Worker object is protected and only gives us the loop in inject # this runs everthing self.Mainframe = Mainframe(self) # this keeps track of what is running self.IsReady: IsReadyStore = IsReadyStore() # connection to phaaze brain self.PhaazeDB: DBConn = DBConn(host=self.Access.PHAAZEDB_HOST, port=self.Access.PHAAZEDB_PORT, user=self.Access.PHAAZEDB_USER, passwd=self.Access.PHAAZEDB_PASSWORD, database=self.Access.PHAAZEDB_DATABASE)
def __init__(self, config: ConfigParser): # if this is not True, the program shuts down immediately self.main = bool(config.get('active_main', True)) self.api: bool = bool(config.get('active_api', False)) self.web: bool = bool(config.get('active_web', False)) self.discord: bool = bool(config.get('active_discord', False)) self.twitch_irc: bool = bool(config.get('active_twitch_irc', False)) self.twitch_events: bool = bool( config.get('active_twitch_events', False)) self.osu_irc: bool = bool(config.get('active_osu_irc', False)) self.twitter: bool = bool(config.get('active_twitter', False)) self.youtube: bool = bool(config.get('active_youtube', False))
def __init__(self, config: ConfigParser): self.DISCORD_MODT: str = str(config.get('discord_motd', 'Hello there')) self.DEFAULT_TWITCH_CURRENCY: str = str( config.get('default_twitch_currency', 'Credit')) self.DEFAULT_TWITCH_CURRENCY_MULTI: str = str( config.get('default_twitch_currency_multi', 'Credits')) self.DEFAULT_DISCORD_CURRENCY: str = str( config.get('default_discord_currency', 'Credit')) self.DEFAULT_DISCORD_CURRENCY_MULTI: str = str( config.get('default_discord_currency_multi', 'Credits')) self.WEB_ROOT: str = str(config.get('web_root', 'localhost')) self.SSL_DIR: str = str( config.get('ssl_dir', '/etc/letsencrypt/live/domain.something/')) self.DISCORD_BOT_ID: str = str(config.get('discord_bot_id', '00000')) self.DISCORD_LOGIN_LINK: str = str( config.get('discord_login_link', '/discord')) self.DISCORD_REDIRECT_LINK: str = str( config.get('discord_redirect_link', 'localhost')) self.LOGO_OSU: str = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d3/Osu%21Logo_%282015%29.png/600px-Osu%21Logo_%282015%29.png" self.LOGO_TWITCH: str = "https://i.redditmedia.com/za3YAsq33WcZc66FVb1cBw6mY5EibKpD_5hfLz0AbaE.jpg?w=320&s=53cf0ff252d84c5bb460b6ec0b195504"
import discord from typing import List from phaazebot import Phaazebot from Platforms.Discord.main_discord import PhaazebotDiscord from Utils.Classes.dbconn import DBConn from Utils.config import ConfigParser from Utils.cli import CliArgs Conf: Optional[ConfigParser] = None for config_source_path in [(CliArgs.get("config") or ""), f"{base_dir}/Config/config.phzcf", f"{base_dir}/Config/config.json"]: if not config_source_path: continue try: Conf = ConfigParser(config_source_path) break except: pass Phaaze: Phaazebot = Phaazebot(PreConfig=Conf) DBC: DBConn = DBConn(host=Phaaze.Config.get("phaazedb_host", "localhost"), port=Phaaze.Config.get("phaazedb_port", "3306"), user=Phaaze.Config.get("phaazedb_user", "phaaze"), passwd=Phaaze.Config.get("phaazedb_password", ""), database=Phaaze.Config.get("phaazedb_database", "phaaze")) class CheckDiscordOnServer(PhaazebotDiscord): def __init__(self): super().__init__(Phaaze)
def __init__(self, PreConfig:ConfigParser=None): if PreConfig: self.Config:ConfigParser = PreConfig else: cfg_path:str = CliArgs.get("config_path", "Config/config.phzcf") cfg_type:str = CliArgs.get("config_type", "phzcf") self.Config:ConfigParser = ConfigParser(file_path=cfg_path, file_type=cfg_type) self.version:str = self.Config.get("version", "[N/A]") self.start_time:float = time.time() # together with another time.time(), used to know how long phaaze is running # log to handler of choice self.Logger:PhaazeLogger = PhaazeLogger() # get the active/load class, aka, what should get started self.Active:ActiveStore = ActiveStore(self) # a class filled with permanent vars, mainly from external sources or whatever self.Vars:VarsStore = VarsStore(self) # the key to everything, that will be needed to connect to everything that's not ourself self.Access:AccessStore = AccessStore(self) # contains user limits for all addable things, like custom command amount self.Limit:LimitStore = LimitStore(self) # all featured "superclasses" aka, stuff that makes calls to somewhere # all of these get added by self.Mainframe when started # both the actual working part and a quick link to there running loops, to inject async functions for them to run # most likely used for the worker, that can calculate time consuming functions or discord because send_message must be called from this loop self.Discord:PhaazebotDiscord = PhaazebotDiscord(self) self.DiscordLoop:Optional[asyncio.AbstractEventLoop] = None self.Twitch:PhaazebotTwitch = PhaazebotTwitch(self) self.TwitchLoop:Optional[asyncio.AbstractEventLoop] = None self.TwitchEvents:PhaazebotTwitchEvents = PhaazebotTwitchEvents(self) self.TwitchEventsLoop:Optional[asyncio.AbstractEventLoop] = None self.Osu:PhaazebotOsu = PhaazebotOsu(self) self.OsuLoop:Optional[asyncio.AbstractEventLoop] = None self.Twitter = None self.TwitterLoop:Optional[asyncio.AbstractEventLoop] = None self.Web:PhaazebotWeb = PhaazebotWeb(self) self.WebLoop:Optional[asyncio.AbstractEventLoop] = None self.WorkerLoop:Optional[asyncio.AbstractEventLoop] = None # Worker object is protected and only gives us the loop in inject # this runs everything self.Mainframe:MainframeThread = MainframeThread(self) # this keeps track of what is running self.IsReady:IsReadyStore = IsReadyStore() # connection to phaaze brain self.PhaazeDB:DBConn = DBConn( host=self.Access.phaazedb_host, port=self.Access.phaazedb_port, user=self.Access.phaazedb_user, passwd=self.Access.phaazedb_password, database=self.Access.phaazedb_database )
# discord_twitch_alert table. # # To be exact the discord_guild_id field. # Because its not really needed for the alerts, but of stat listing etc. # This protocol is suppost to try finding the GuildID based on the ChannelID # import os import sys sys.path.insert(0, f"{os.path.dirname(__file__)}/../../") import discord import asyncio from Utils.Classes.dbconn import DBConn from Utils.config import ConfigParser Configs: ConfigParser = ConfigParser() class PhaazeDiscordConnection(discord.Client): """ Discord connection for running the protocol """ def __init__(self, empty_entrys: list): super().__init__() self.empty_entrys = empty_entrys async def on_ready(self) -> None: global DBC print("Discord Connectet, running checks...") for entry in self.empty_entrys: channel_id: str = entry.get("discord_channel_id", "") if not channel_id:
def __init__(self, config: ConfigParser): self.TWITCH_API_TOKEN: str = str(config.get('twitch_api_token', '')) self.TWITCH_IRC_TOKEN: str = str(config.get('twitch_irc_token', '')) self.TWITCH_ADMIN_TOKEN: str = str(config.get('twitch_admin_token', '')) self.DISCORD_TOKEN: str = str(config.get('discord_token', '')) self.DISCORD_SECRET: str = str(config.get('discord_secret', '')) self.OSU_API_TOKEN: str = str(config.get('osu_api_token', '')) self.OSU_IRC_USERNAME: str = str(config.get('osu_irc_username', '')) self.OSU_IRC_TOKEN: str = str(config.get('osu_irc_token', '')) self.CLEVERBOT_TOKEN: str = str(config.get('cleverbot_token', '')) self.MASHAPE_TOKEN: str = str(config.get('mashape_token', '')) self.PHAAZEDB_HOST: str = str(config.get('phaazedb_host', 'localhost')) self.PHAAZEDB_PORT: str = str(config.get('phaazedb_port', '3306')) self.PHAAZEDB_USER: str = str(config.get('phaazedb_user', 'phaaze')) self.PHAAZEDB_PASSWORD: str = str(config.get('phaazedb_password', '')) self.PHAAZEDB_DATABASE: str = str( config.get('phaazedb_database', 'phaaze')) self.TWITTER_TOKEN: str = str(config.get('twitter_token', '')) self.TWITTER_TOKEN_KEY: str = str(config.get('twitter_token_key', '')) self.TWITTER_CONSUMER_KEY: str = str( config.get('twitter_consumer_key', '')) self.TWITTER_CONSUMER_SECRET: str = str( config.get('twitter_consumer_secret', ''))
def __init__(self, config: ConfigParser): self.DISCORD_PRIVATE_COOLDOWN: int = int( config.get("discord_private_cooldown", 1)) self.DISCORD_NORMAL_COOLDOWN: int = int( config.get("discord_normal_cooldown", 1)) self.DISCORD_MOD_COOLDOWN: int = int( config.get("discord_mod_cooldown", 3)) self.DISCORD_OWNER_COOLDOWN: int = int( config.get("discord_owner_cooldown", 5)) self.DISCORD_COMMANDS_AMOUNT: int = int( config.get("discord_custom_commands_amount", 100)) self.DISCORD_COMMANDS_COOLDOWN_MIN: int = int( config.get("discord_custom_commands_cooldown_min", 3)) self.DISCORD_COMMANDS_COOLDOWN_MAX: int = int( config.get("discord_custom_commands_cooldown_max", 600)) self.DISCORD_LEVEL_COOLDOWN: int = int( config.get("discord_level_cooldown", 3)) self.DISCORD_LEVEL_MEDAL_AMOUNT: int = int( config.get("discord_level_medal_amount", 50)) self.DISCORD_QUOTES_AMOUNT: int = int( config.get("discord_quotes_amount", 100)) self.DISCORD_ASSIGNROLE_AMOUNT: int = int( config.get("discord_assignrole_amount", 25)) self.TWITCH_TIMEOUT_MESSAGE_COOLDOWN: int = int( config.get("twitch_timeout_message_cooldown", 20)) self.TWITCH_BLACKLIST_REMEMBER_TIME: int = int( config.get("twitch_blacklist_remember_time", 180)) self.TWITCH_CUSTOM_COMMAND_AMOUNT: int = int( config.get("twitch_custom_command_amount", 100)) self.TWITCH_QUOTE_AMOUNT: int = int( config.get("twitch_quote_amount", 100)) self.TWITCH_STATS_COOLDOWN: int = int( config.get("twitch_stats_cooldown", 5)) self.WEB_CLIENT_MAX_SIZE: int = int( config.get("web_client_max_size", 5242880)) #5MB