def __init__(self): self.discord = DiscordApi(self.web_hook) self.tasks = {} subreddit = 'battlecats' keywords = ['[BCJP]', '[BCEN]', '[Announcement]', 'new', 'New', 'PONOS', 'Ponos', 'Update', 'update'] for account in self.accounts.split(","): self.tasks[account] = RedditRss(subreddit, keywords)
class RedditTask: web_hook = os.environ.get('BATTLECAT_WEBHOOK') accounts = os.environ.get('REDDIT_ACCOUNTS') def __init__(self): self.discord = DiscordApi(self.web_hook) self.tasks = {} subreddit = 'battlecats' keywords = ['[BCJP]', '[BCEN]', '[Announcement]', 'new', 'New', 'PONOS', 'Ponos', 'Update', 'update'] for account in self.accounts.split(","): self.tasks[account] = RedditRss(subreddit, keywords) def handle_feed(self, entry): print(entry.author) print(entry.title) print(entry.link) message = '\n==============================\n【Reddit】{}\'s new post\n==============================\n\n'.format(entry.author)+entry.title+'\n'+entry.link self.discord.send_discord_message(message) def execute(self): print("Starting up RedditTask....") while(True): print("Looping.......") for account in self.accounts.split(","): print("For account {}".format(account)) self.tasks[account].read_rss(account, self.handle_feed) time.sleep(1) time.sleep(60)
def __init__(self, consumer_key, consumer_secret, access_token, access_secret): self.twitter = TwitterApi(consumer_key, consumer_secret, access_token, access_secret) self.discord = DiscordApi(self.web_hook, self.names, self.avatars) self.handle = { self.account_jp_id: self.handle_tweet_jp, self.account_en_id: self.handle_tweet_en }
def __init__(self, consumer_key, consumer_secret, access_token, access_secret): self.twitter = TwitterApi(consumer_key, consumer_secret, access_token, access_secret) self.discord = DiscordApi(self.web_hook, self.names, self.avatars) self.spr5_discord = DiscordApi(self.spr5_web_hook, self.spr5_names, self.spr5_avatars) self.handle = { self.account_id: self.handle_tweet_ac, self.spr5_id: self.handle_tweet_spr5, self.anime_id: self.handle_tweet_anime, self.afterlost_id: self.handle_tweet_afterlost, self.afterlost_en_id: self.handle_tweet_afterlost }
class BCTask: account_jp_id = os.environ.get('BCJP_ACCOUNT_ID') account_en_id = os.environ.get('BCEN_ACCOUNT_ID') web_hook = os.environ.get('BATTLECAT_WEBHOOK') names = os.environ.get('BC_BOT_NAMES') avatars = os.environ.get('BC_BOT_AVATARS') translator = Translator() def __init__(self, consumer_key, consumer_secret, access_token, access_secret): self.twitter = TwitterApi(consumer_key, consumer_secret, access_token, access_secret) self.discord = DiscordApi(self.web_hook, self.names, self.avatars) self.handle = { self.account_jp_id: self.handle_tweet_jp, self.account_en_id: self.handle_tweet_en } def handle_tweet_jp(self, tweet): try: text = self.translator.translate(tweet.text, dest='en').text except: print("Error translating tweet: {}".format(tweet.text)) text = tweet.text message = '\n==============================\n【Twitter】【BCJP】- Battle Cat JP Twitter\n==============================\n\n'+text self.discord.send_discord_message(message) def handle_tweet_en(self, tweet): message = '\n==============================\n【Twitter】【BCEN】- Battle Cat EN Twitter\n==============================\n\n'+tweet.text self.discord.send_discord_message(message) def handle_tweet(self, tweet): self.handle[tweet.userId](tweet) def execute(self): print("Starting up BCTask....") account_ids = [self.account_en_id, self.account_jp_id] self.twitter.on_status_change(account_ids, self.handle_tweet)
def __init__(self, subreddit, keywords): self.discord = DiscordApi(self.web_hook) self.regex = re.compile('.*reddit.com/r/{}/.*'.format(subreddit)) self.keywords = keywords redis_url = os.getenv('REDISTOGO_URL', 'redis://localhost:6379') self.redis = redis.from_url(redis_url)
class ACTask: account_id = os.environ.get('TWITTER_ACCOUNT_ID') spr5_id = os.environ.get('SPR5_ACCOUNT_ID') anime_id = os.environ.get('AC_ANIME_ACCOUNT_ID') afterlost_id = os.environ.get('AFTERLOST_ACCOUNT_ID') afterlost_en_id = os.environ.get('AFTERLOST_EN_ACCOUNT_ID') web_hook = os.environ.get('DISCORD_WEBHOOK') names = os.environ.get('AC_BOT_NAMES') avatars = os.environ.get('AC_BOT_AVATARS') spr5_web_hook = os.environ.get('SPR5_WEBHOOK') spr5_names = os.environ.get('SPR5_BOT_NAMES') spr5_avatars = os.environ.get('SPR5_BOT_AVATARS') translator = Translator() def __init__(self, consumer_key, consumer_secret, access_token, access_secret): self.twitter = TwitterApi(consumer_key, consumer_secret, access_token, access_secret) self.discord = DiscordApi(self.web_hook, self.names, self.avatars) self.spr5_discord = DiscordApi(self.spr5_web_hook, self.spr5_names, self.spr5_avatars) self.handle = { self.account_id: self.handle_tweet_ac, self.spr5_id: self.handle_tweet_spr5, self.anime_id: self.handle_tweet_anime, self.afterlost_id: self.handle_tweet_afterlost, self.afterlost_en_id: self.handle_tweet_afterlost } def handle_tweet_ac(self, tweet): try: text = self.translator.translate(tweet.text, dest='en').text except: print("Error translating tweet: {}".format(tweet.text)) text = tweet.text message = '\n==============================\n【Twitter】【AC】\n==============================\n\n' + text self.discord.send_discord_message(message) def handle_tweet_spr5(self, tweet): try: text = self.translator.translate(tweet.text, dest='en').text except: print("Error translating tweet: {}".format(tweet.text)) text = tweet.text message = '\n==============================\n【Twitter】【SPR5】\n==============================\n\n' + text self.spr5_discord.send_discord_message(message) def handle_tweet_anime(self, tweet): try: text = self.translator.translate(tweet.text, dest='en').text except: print("Error translating tweet: {}".format(tweet.text)) text = tweet.text message = '\n==============================\n【Twitter】【ANIME】\n==============================\n\n' + text self.discord.send_discord_message(message) def handle_tweet_afterlost(self, tweet): try: text = self.translator.translate(tweet.text, dest='en').text except: print("Error translating tweet: {}".format(tweet.text)) text = tweet.text message = '\n==============================\n【Twitter】【AFTER LOST】\n==============================\n\n' + text self.discord.send_discord_message(message) def handle_tweet(self, tweet): self.handle[tweet.userId](tweet) def execute(self): print("Starting up ACTask....") account_ids = [ self.account_id, self.spr5_id, self.anime_id, self.afterlost_id, self.afterlost_en_id ] self.twitter.on_status_change(account_ids, self.handle_tweet)