-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrogbot_discord.py
158 lines (137 loc) · 5.9 KB
/
frogbot_discord.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import discord,os,asyncio,sys
from discord.ext import commands
from funcs import *
from random import choice
import wordcloud
import pandas as pd
from datetime import datetime
import matplotlib.pyplot as plt
frogpants_channel = 'https://www.youtube.com/channel/UCIEIRz-KpYoEPnrNQuyHwJw'
showbot_channel = 'Frogpants'
with open('../showbot_token.txt',"r") as f:
token = f.readlines()[0]
url = f'https://tms.showbot.tv/'
with open('../frogbot_token.txt',"r") as f:
disc_token = f.readlines()[0]
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!',intents=intents)
intents.members = True
intents.message_content = True
intents.guilds = True
intents.presences = True
intents.guild_messages = True
author_index,submitted_titles,times = build_submission_history(showbot_channel)
bacon_gifs = os.listdir('bacon_gifs')
def get_channel(guild_id,channel_id):
guild_obj = bot.get_guild(guild_id)
channel_obj = guild_obj.get_channel(channel_id)
return guild_obj,channel_obj
frogpants_guild_id = 146848379853471744
test_channel_id = 1308868510037839884
frogpants_general = 623339707715158016
frogpants_tms = 146848379853471744
frogpants_monday_show = 1207082163703648356
testbed_guild_id = 675451203412295779
testbed_general_id = 675451203907354626
os.environ['detected']='False'
os.environ['last_link'] = 'None'
##DON'T FORGET TO AWAIT THE SLEEP FUNCTIONS
async def time_check(channel_obj):
while True:
detected = os.environ['detected']
if detected == 'False':
print('Detected = False')
detected,livestream_link = detect_stream(frogpants_channel)
if detected and livestream_link is not None:
print('Stream detected.')
await channel_obj.send(f'Looks like Frogpants has gone live! Watch at: {livestream_link}',delete_after = one_hour)
os.environ['detected'] = 'True'
else:
print('No stream detected.')
print('Sleeping search for 15 minutes.')
await asyncio.sleep(15*one_minute)
else:
print('Sleeping search for 3 hours.')
await asyncio.sleep(3*one_hour)
os.environ['detected']='False'
@bot.event
async def on_ready():
print("Let's roll, buttholes!")
frogpants_guild_obj,general_channel_obj = get_channel(frogpants_guild_id,frogpants_general)
frogpants_guild_obj,test_channel_obj = get_channel(frogpants_guild_id,test_channel_id)
if frogpants_guild_obj is not None:
print(f'Guild object found: {frogpants_guild_obj}')
else:
print('No guild object found.')
if test_channel_obj is not None:
print(f'Channel object found: {test_channel_obj}')
if 'quiet' not in sys.argv:
await test_channel_obj.send("Let's roll, buttholes!",delete_after = one_minute)
else:
print(f'Test channel object found: {test_channel_obj}, but quiet mode is active; ergo no message will be sent.')
else:
print('No channel object found, no Discord message will be sent.')
if general_channel_obj is not None:
print('Launching and syncing live stream detection.')
await time_check(general_channel_obj)
else:
print('No general channel object found, halting live stream detection.')
one_hour = 3600
one_minute = 60
@bot.command()
async def live(ctx):
detected = os.environ['detected']
if detected == 'True':
_,livestream_link = detect_stream(frogpants_channel)
await ctx.send(f'Looks like Frogpants has gone live! Watch at: {livestream_link}',delete_after=one_hour)
else:
await ctx.send("I don't seem to be able to find a live stream for Frogpants.",delete_after = one_minute)
@bot.command()
async def s(ctx):
author = ctx.message.author.display_name
title = (ctx.message.content)[3:]
author_index.append(author)
submitted_titles.append(title)
print(f'{author}: {title}') #Add new title to list and add author to another list to maintain the order. Print for debugging and monitoring purposes.
author_html,title_html = html_ify(author),html_ify(title) #Prepare link for submission then submit via Requests module
submission_link = f'http://www.showbot.tv/s/add.php?title={title_html}&user={author_html}&channel={showbot_channel}&key={token}'
try:
submission = requests.get(submission_link)
print(submission)
confirmation_message = randomize_confirmation(author,disc_format=True)
await ctx.reply(confirmation_message)
except TimeoutError:
print('Timeout error')
@bot.command(pass_context=True)
async def guild_info(ctx):
guild_id = ctx.message.guild.id
channel = ctx.message.channel.id
guild = bot.get_guild(guild_id)
print(guild_id)
print(channel)
print(guild.channels)
@bot.command()
async def showbot(ctx):
await ctx.send(f"Don't forget to vote for titles! {url}",delete_after = one_minute*5)
@bot.command()
async def wc(ctx):
show = 'TMS'
df_name = f'{show}-{datetime.today().year}-{datetime.today().month}-{datetime.today().day}.csv'
cloud_name = f'{show}-{datetime.today().year}-{datetime.today().month}-{datetime.today().day}.png'
df = pd.read_csv(f'archive/{df_name}',encoding='utf-8')
text = ' '.join(df.title.tolist())
cloud = wordcloud.WordCloud().generate(text)
cloud.to_file(f'word_clouds/{cloud_name}')
await ctx.send(f"Word cloud of today's show titles!")
await ctx.send(file=discord.File(f'word_clouds/{cloud_name}'))
@bot.command()
async def bacon(ctx):
rando_gif = choice(bacon_gifs)
gif_fp = os.path.join(os.getcwd(),'bacon_gifs',rando_gif)
await ctx.send(file=discord.File(gif_fp),delete_after = one_minute*5)
@bot.command()
async def kill(ctx):
if ('Mod' in [str(i) for i in ctx.author.roles]) or (str(ctx.author) == 'talizorel') or (str(ctx.author) == 'frogpants'):
await ctx.send('Ouch, right in the butthole.',delete_after = one_minute)
exit()
bot.run(disc_token)