Skip to content

Commit e2d6fdc

Browse files
committed
remove twitter, warframe, zkillboard
also remove reddit_access_token (usage removed in adda487)
1 parent f7a2c12 commit e2d6fdc

7 files changed

Lines changed: 0 additions & 422 deletions

File tree

bot.py

Lines changed: 0 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import datetime
44
import importlib
55
import json
6-
import mimetypes
76
import os
87
import random
98
import re
@@ -27,8 +26,6 @@
2726
import sbds
2827
import steam_news
2928
import twitch
30-
import twitter
31-
import warframe
3229
from timer import readable_rel
3330

3431
class Bot:
@@ -48,11 +45,7 @@ def __init__(self, commands):
4845
self.timer_thread = None
4946
self.timer_condvar = threading.Condition()
5047
self.zkill_thread = None
51-
self.warframe_thread = None
5248
self.twitch_thread = None
53-
self.twitter_thread = None
54-
self.twitter_post_thread = None
55-
self.twitter_post_condvar = threading.Condition()
5649
self.instagram_thread = None
5750
self.steam_news_thread = None
5851
self.advent_of_code_thread = None
@@ -66,8 +59,6 @@ def __init__(self, commands):
6659
'READY': self.handle_ready,
6760
'MESSAGE_CREATE': self.handle_message_create,
6861
'INTERACTION_CREATE': self.handle_interaction_create,
69-
'MESSAGE_REACTION_ADD': self.handle_reaction_add,
70-
'MESSAGE_REACTION_REMOVE': self.handle_reaction_remove,
7162
'GUILD_CREATE': self.handle_guild_create,
7263
'GUILD_ROLE_CREATE': self.handle_guild_role_create,
7364
'GUILD_ROLE_UPDATE': self.handle_guild_role_update,
@@ -258,16 +249,10 @@ def handle_ready(self, d):
258249
if self.timer_thread is not None:
259250
return
260251
self.timer_thread = _thread.start_new_thread(self.timer_loop, ())
261-
if config.bot.zkillboard is not None:
262-
self.zkill_thread = _thread.start_new_thread(self.zkill_loop, ())
263252
if config.bot.warframe is not None:
264253
self.warframe_thread = _thread.start_new_thread(self.warframe_loop, ())
265254
if config.bot.twitch is not None:
266255
self.twitch_thread = _thread.start_new_thread(self.twitch_loop, ())
267-
if config.bot.twitter is not None:
268-
self.twitter_thread = _thread.start_new_thread(self.twitter_loop, ())
269-
if config.bot.twitter_post is not None:
270-
self.twitter_post_thread = _thread.start_new_thread(self.twitter_post_loop, ())
271256
if config.bot.instagram is not None:
272257
self.instagram_thread = _thread.start_new_thread(self.instagram_loop, ())
273258
if config.bot.steam_news is not None:
@@ -349,59 +334,6 @@ def _autoreload(self, command_name, handler):
349334
# continue replacing all the commands in the reloaded file; do not break/return
350335
return handler
351336

352-
def handle_reaction_add(self, d):
353-
if config.bot.twitter_post is None:
354-
return
355-
356-
if d['channel_id'] != config.bot.twitter_post['channel'] or \
357-
d['emoji']['name'] != 'shrfood_twitter' or d['user_id'] == self.user_id:
358-
return
359-
360-
if d['message_id'] in config.state.twitter_queue:
361-
return
362-
363-
message = self.get_message(d['channel_id'], d['message_id'])
364-
attachments = message.get('attachments')
365-
if not attachments:
366-
self.react(d['channel_id'], d['message_id'], '🙈')
367-
return
368-
369-
for attachment in attachments[:4]:
370-
media_type, _ = mimetypes.guess_type(attachment['filename'])
371-
if media_type.startswith('video/'):
372-
if len(attachments) != 1:
373-
self.react(d['channel_id'], d['message_id'], '🧐')
374-
return
375-
if attachment['size'] > 5000000:
376-
self.react(d['channel_id'], d['message_id'], '😓')
377-
return
378-
379-
config.state.twitter_queue.append(d['message_id'])
380-
config.state.save()
381-
382-
self.react(d['channel_id'], d['message_id'], '✅')
383-
with self.twitter_post_condvar:
384-
self.twitter_post_condvar.notify()
385-
386-
def handle_reaction_remove(self, d):
387-
if config.bot.twitter_post is None:
388-
return
389-
390-
if d['channel_id'] != config.bot.twitter_post['channel'] or \
391-
d['emoji']['name'] != 'shrfood_twitter':
392-
return
393-
394-
emoji = '%s:%s' % (d['emoji']['name'], d['emoji']['id'])
395-
reactions = self.get_reactions(d['channel_id'], d['message_id'], emoji)
396-
if len(reactions) == 0: # no more shrfood_twitter emoji
397-
try:
398-
config.state.twitter_queue.remove(d['message_id'])
399-
except ValueError:
400-
return
401-
config.state.save()
402-
403-
self.remove_reaction(d['channel_id'], d['message_id'], '✅')
404-
405337
def handle_guild_create(self, d):
406338
log.write('in guild %s (%d members)' % (d['name'], d['member_count']))
407339
self.guilds[d['id']] = Guild(d)
@@ -465,52 +397,6 @@ def timer_loop(self):
465397
with self.timer_condvar:
466398
self.timer_condvar.wait(wakeup)
467399

468-
def zkill_loop(self):
469-
while True:
470-
r = self.rs.get('https://redisq.zkillboard.com/listen.php', params={'ttw': 30})
471-
if r.ok:
472-
data = r.json()
473-
if not data or not data['package']:
474-
time.sleep(10)
475-
continue
476-
killmail = data['package']['killmail']
477-
victim = killmail['victim']
478-
479-
characters = killmail['attackers']
480-
characters.append(victim)
481-
for char in characters:
482-
if 'alliance' in char and char['alliance']['id'] == config.bot.zkillboard['alliance']:
483-
break
484-
else: # alliance not involved in kill
485-
continue
486-
487-
if 'character' not in victim:
488-
continue
489-
victim_name = victim['character']['name']
490-
ship = victim['shipType']['name']
491-
cost = data['package']['zkb']['totalValue'] / 1000000
492-
url = 'https://zkillboard.com/kill/%d/' % killmail['killID']
493-
self.send_message(config.bot.zkillboard['channel'],
494-
"%s's **%s** (%d mil) %s" % (victim_name, ship, cost, url))
495-
else:
496-
log.write('zkill: %s %s\n%s' % (r.status_code, r.reason, r.text[:1000]))
497-
time.sleep(30)
498-
499-
def warframe_loop(self):
500-
last_alerts = []
501-
while True:
502-
time.sleep(5 * 60)
503-
try:
504-
alerts = warframe.alert_analysis()
505-
broadcast_alerts = set(alerts) - set(last_alerts)
506-
if len(broadcast_alerts) > 0:
507-
self.send_message(config.bot.warframe['channel'], '\n'.join(broadcast_alerts))
508-
last_alerts = alerts
509-
except requests.exceptions.HTTPError as e:
510-
log.write('warframe: %s\n%s' % (e, e.response.text[:1000]))
511-
except requests.exceptions.RequestException as e:
512-
log.write('warframe: %s' % e)
513-
514400
def twitch_loop(self):
515401
while True:
516402
# https://dev.twitch.tv/docs/api/guide#rate-limits
@@ -523,48 +409,6 @@ def twitch_loop(self):
523409
except requests.exceptions.RequestException as e:
524410
log.write('twitch: %s' % e)
525411

526-
def twitter_loop(self):
527-
while True:
528-
# https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline.html
529-
# 100,000 in 24 hours is 69.4 a minute, so wait 1 minute per account (1 request per account)
530-
time.sleep(60 * len(config.bot.twitter['accounts']))
531-
try:
532-
twitter.new_tweets(self)
533-
except requests.exceptions.HTTPError as e:
534-
log.write('twitter: %s\n%s' % (e, e.response.text[:1000]))
535-
except requests.exceptions.RequestException as e:
536-
log.write('twitter: %s' % e)
537-
538-
def twitter_post_loop(self):
539-
while True:
540-
if len(config.state.twitter_queue) == 0:
541-
with self.twitter_post_condvar:
542-
self.twitter_post_condvar.wait()
543-
continue
544-
545-
sleep = 12 * 60 * 60 # 12 hours
546-
if config.state.twitter_last_post_time:
547-
sleep = config.state.twitter_last_post_time + sleep - time.time()
548-
with self.twitter_post_condvar:
549-
self.twitter_post_condvar.wait(sleep)
550-
if config.state.twitter_last_post_time and \
551-
time.time() < config.state.twitter_last_post_time + 12 * 60 * 60:
552-
# we were woken up by a reaction add but it's too early
553-
continue
554-
555-
try:
556-
twitter.post(self, config.state.twitter_queue[0])
557-
config.state.twitter_queue.pop(0)
558-
except requests.exceptions.HTTPError as e:
559-
log.write('twitter: %s\n%s' % (e, e.response.text[:1000]))
560-
except requests.exceptions.RequestException as e:
561-
log.write('twitter: %s' % e)
562-
except Exception:
563-
log.write('twitter post:\n' + traceback.format_exc())
564-
# always update the last post time, even if we failed to tweet
565-
config.state.twitter_last_post_time = int(time.time())
566-
config.state.save()
567-
568412
def instagram_loop(self):
569413
while True:
570414
# https://developers.facebook.com/docs/graph-api/overview/rate-limiting#platform-rate-limits

commands.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import poe
1111
import sbds
1212
import timer
13-
import twitter
1413
import utils
1514

1615
commands = {
@@ -60,7 +59,5 @@
6059
'fc': friend_code.friend_code,
6160
'stalks': animal_crossing.stalk_market,
6261

63-
'twitter_queue': twitter.queue_info,
64-
6562
'can': canned.canned,
6663
}

config.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ def __str__(self):
3535
'flights': [],
3636
'gateway_url': None,
3737
'instagram': {},
38-
'reddit_access_token': None,
3938
'steam_news_ids': {},
4039
'timers': {},
4140
'tweet_ids': {},
4241
'twitch_last_times': {},
43-
'twitter_last_post_time': None,
44-
'twitter_queue': [],
4542
})

config.yaml.example

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,6 @@ err_channel: null
44
roles: # set this to null to disable
55
server: '109469702010478592' # secret hiding room
66
eve_db: 'sqlite-latest.sqlite'
7-
zkillboard: # set this to null to disable
8-
alliance: 99002172
9-
channel: '282441291327864834'
10-
twitter: # set this to null to disable
11-
bearer_token: null
12-
accounts:
13-
RiskofRain: '282441291327864834'
14-
twitter_post: # set this to null to disable
15-
consumer_key: null # get these from https://developer.twitter.com/en/apps/
16-
consumer_secret: null
17-
token: null # get these from twitter_key.py
18-
token_secret: null
19-
server: '109469702010478592' # secret hiding room
20-
channel: '316959344681943040' # food
217
instagram: # set this to null to disable
228
- user_id: 17841443895269721 # cocoshibanut
239
channels:
@@ -35,8 +21,6 @@ twitch: # set this to null to disable
3521
mention: '&1173144877127696394' # test role
3622
steam_news: # set this to null to disable
3723
427520: '282441291327864834' # factorio -> #bot-testing
38-
warframe: # set this to null to disable
39-
channel: '326069638477774861'
4024
acnh_db: 'acnh.sqlite' # set this to null to disable
4125
advent_of_code: # set this to null to disable
4226
- leaderboard: 660957 # Frosty-nee

0 commit comments

Comments
 (0)