Exemple #1
0
    def __init__(self, bot):
        self.bot = bot

        self.twitter_client = None
        self.listener = None

        if self.bot:
            HandlerManager.add_handler("twitter_follows",
                                       self.on_twitter_follows)

        if "twitter" not in bot.config:
            return

        twitter_config = bot.config["twitter"]

        if not (twitter_config.get("consumer_key", False)
                and twitter_config.get("consumer_secret", False)
                and twitter_config.get("access_token", False)
                and twitter_config.get("access_token_secret", False)):
            return

        try:
            self.twitter_auth = tweepy.OAuthHandler(
                twitter_config["consumer_key"],
                twitter_config["consumer_secret"])
            self.twitter_auth.set_access_token(
                twitter_config["access_token"],
                twitter_config["access_token_secret"])

            self.twitter_client = tweepy.API(self.twitter_auth)
        except:
            log.exception("Twitter authentication failed.")
            self.twitter_client = None
Exemple #2
0
    def __init__(self, config, args):
        self.config = config
        self.args = args
        self.private_loop = asyncio.get_event_loop()
        self.private_loop.set_exception_handler(custom_exception_handler)

        self.discord_token = self.config["main"]["discord_token"]

        ScheduleManager.init(self.private_loop)

        DBManager.init(self.config["main"]["db"])

        ActionParser.bot = self

        # redis
        redis_options = {}
        if "redis" in config:
            redis_options = dict(config.items("redis"))
        RedisManager.init(**redis_options)
        utils.wait_for_redis_data_loaded(RedisManager.get())

        # SQL migrations
        try:
            with DBManager.create_dbapi_connection_scope() as sql_conn:
                sql_migratable = DatabaseMigratable(sql_conn)
                sql_migration = Migration(sql_migratable,
                                          greenbot.migration_revisions.db,
                                          self)
                sql_migration.run()
        except ValueError as error:
            log.error(error)

        HandlerManager.init_handlers()

        self.movienight_api = MovieNightAPI(self, self.config["wsc"],
                                            self.config["wowza_cdn"])

        HandlerManager.add_handler("parse_command_from_message",
                                   self.parse_command_from_message)
        self.bot_name = self.config["main"]["bot_name"]
        self.command_prefix = self.config["discord"]["command_prefix"]
        self.settings = {
            "discord_token": self.discord_token,
            "bot_name": self.bot_name,
            "command_prefix": self.command_prefix,
            "discord_guild_id": self.config["discord"]["discord_guild_id"],
        }

        HandlerManager.add_handler("discord_ready", self.wait_discord_load)

        self.discord_bot = DiscordBotManager(
            bot=self,
            settings=self.settings,
            redis=RedisManager.get(),
            private_loop=self.private_loop,
        )
        self.twitter_manager = TwitterManager(self)
        self.filters = Filters(self, self.discord_bot)
        self.functions = Functions(self, self.filters)
Exemple #3
0
 def enable(self, bot):
     if not bot:
         return
     if not self.bot.movienight_api.active:
         log.error("API is not running!")
         return
     
     HandlerManager.add_handler("movie_night_started", self.movie_night_started_event)
Exemple #4
0
    def __init__(self, bot, settings, redis, private_loop):
        self.bot = bot
        self.settings = settings
        self.client = CustomClient(self)

        self.private_loop = private_loop
        self.redis = redis

        self.guild = None
        if not self.redis.get("timeouts-discord") or not json.loads(self.redis.get("timeouts-discord")):
            self.redis.set("timeouts-discord", json.dumps({}))
        
        HandlerManager.add_handler("discord_ready", self.initial_unbans)
Exemple #5
0
    def enable(self, bot):
        if not bot:
            return

        HandlerManager.add_handler("on_message", self.on_message, priority=100)
        HandlerManager.add_handler("on_commit", self.on_commit)

        if self.db_session is not None:
            self.db_session.commit()
            self.db_session.close()
            self.db_session = None
        self.db_session = DBManager.create_session()
        self.blacklisted_links = []
        for link in self.db_session.query(BlacklistedLink):
            self.blacklisted_links.append(link)

        self.whitelisted_links = []
        for link in self.db_session.query(WhitelistedLink):
            self.whitelisted_links.append(link)
Exemple #6
0
    def enable(self, bot):
        if not bot:
            return

        HandlerManager.add_handler("discord_raw_message_edit", self.message_edit)
        HandlerManager.add_handler("discord_raw_message_delete", self.message_delete)
        HandlerManager.add_handler("discord_member_update", self.member_update)
        HandlerManager.add_handler("discord_guild_role_update", self.role_update)
        HandlerManager.add_handler("discord_guild_role_create", self.role_create)
        HandlerManager.add_handler("discord_guild_role_delete", self.role_delete)
        HandlerManager.add_handler("discord_voice_state_update", self.voice_change)
        HandlerManager.add_handler("discord_member_remove", self.member_remove)
        HandlerManager.add_handler("discord_member_join", self.member_join)
        HandlerManager.add_handler("discord_guild_channel_update", self.channel_update)
        HandlerManager.add_handler("discord_guild_channel_create", self.channel_create)
        HandlerManager.add_handler("discord_guild_channel_delete", self.channel_delete)
        HandlerManager.add_handler("discord_guild_update", self.guild_update)
        HandlerManager.add_handler("discord_guild_emojis_update", self.emoji_update)
        HandlerManager.add_handler("discord_invite_create", self.invite_create)
        HandlerManager.add_handler("discord_invite_delete", self.invite_delete)
        HandlerManager.add_handler("aml_custom_log", self.custom_event_log)
Exemple #7
0
 def __init__(self, bot):
     self.bot = bot
     HandlerManager.add_handler("discord_message", self.on_message)
     HandlerManager.add_handler("discord_raw_message_edit",
                                self.edit_message,
                                priority=1000)
Exemple #8
0
 def enable(self, bot):
     if not bot:
         return
     HandlerManager.add_handler("twitter_on_status", self.on_status)