-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui_components.py
More file actions
186 lines (161 loc) · 8.25 KB
/
ui_components.py
File metadata and controls
186 lines (161 loc) · 8.25 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import csv
import discord
from discord.ui import *
from dotenv import load_dotenv
import os
load_dotenv()
provider_url = os.getenv('PROVIDER_URL')
class MovieButton(Button):
def __init__(self, movie):
self.movie = movie
super().__init__(label=self.movie.name, url=f'{provider_url}?video_id={self.movie.imdb_id}')
class Movie:
def __init__(self, imdb_id, name):
self.imdb_id = imdb_id
self.name = name
class TVShow:
def __init__(self, series, season=1, episode=1):
self.imdb_id = series['imdbID']
self.title = series['Title']
self.season = season
self.episode = episode
class NextButton(Button):
def __init__(self, embed, tvshow):
self.embed = embed
self.tvshow = tvshow
super().__init__(label='Next Episode', custom_id='next_button')
async def callback(self, interaction: discord.Interaction):
self.tvshow.episode += 1
self.embed.url = f'{provider_url}?video_id={self.tvshow.imdb_id}&s={self.tvshow.season}&e={self.tvshow.episode}'
await interaction.response.edit_message(content=f'{self.tvshow.title} S{self.tvshow.season} E{self.tvshow.episode}', view=self.view, embed=self.embed)
class PreviousButton(Button):
def __init__(self, embed, tvshow):
self.embed = embed
self.tvshow = tvshow
super().__init__(label='Previous Episode', custom_id='previous_button')
async def callback(self, interaction: discord.Interaction):
self.tvshow.episode = max(1, self.tvshow.episode - 1)
self.embed.url = f'{provider_url}?video_id={self.tvshow.imdb_id}&s={self.tvshow.season}&e={self.tvshow.episode}'
await interaction.response.edit_message(content=f'{self.tvshow.title} S{self.tvshow.season} E{self.tvshow.episode}', view=self.view, embed=self.embed)
class NextSeasonButton(Button):
def __init__(self, embed, tvshow):
self.embed = embed
self.tvshow = tvshow
super().__init__(label='Next Season', custom_id='next_season_button')
async def callback(self, interaction: discord.Interaction):
self.tvshow.season += 1
self.tvshow.episode = 1
self.embed.url = f'{provider_url}?video_id={self.tvshow.imdb_id}&s={self.tvshow.season}&e={self.tvshow.episode}'
await interaction.response.edit_message(content=f'{self.tvshow.title} S{self.tvshow.season} E{self.tvshow.episode}', view=self.view, embed=self.embed)
class PreviousSeasonButton(Button):
def __init__(self, embed, tvshow):
self.embed = embed
self.tvshow = tvshow
super().__init__(label='Previous Season', custom_id='previous_season_button')
async def callback(self, interaction: discord.Interaction):
self.tvshow.season = max(1, self.tvshow.season - 1)
self.tvshow.episode = 1
self.embed.url = f'{provider_url}?video_id={self.tvshow.imdb_id}&s={self.tvshow.season}&e={self.tvshow.episode}'
await interaction.response.edit_message(content=f'{self.tvshow.title} S{self.tvshow.season} E{self.tvshow.episode}', view=self.view, embed=self.embed)
class SeriesButton(Button):
def __init__(self, tvshow, ctx, bot, private=None):
self.tvshow = tvshow
self.ctx = ctx
self.bot = bot
if private is not None:
self.private = private
else:
with open('settings.csv', 'r') as file:
csv_reader = csv.reader(file)
rows = [row for row in csv_reader]
for row in rows[1:]:
if row[0] == str(ctx.user.id):
self.private = True if row[1] == 'True' else False
else:
self.private = False
super().__init__(label=self.tvshow.title)
async def callback(self, interaction: discord.Interaction):
await interaction.response.defer()
existing_thread = discord.utils.get(self.ctx.guild.threads, name=self.tvshow.title)
if existing_thread and not self.private:
thread = existing_thread
else:
thread = await self.ctx.channel.create_thread(name=self.tvshow.title, type=discord.ChannelType.private_thread if self.private else discord.ChannelType.public_thread)
self.embed = discord.Embed(title=f'{self.tvshow.title}', url=f'{provider_url}?video_id={self.tvshow.imdb_id}&s={self.tvshow.season}&e={self.tvshow.episode}', color=discord.Color.blue())
self.next_button = NextButton(embed=self.embed, tvshow=self.tvshow)
self.previous_button = PreviousButton(embed=self.embed, tvshow=self.tvshow)
self.next_season_button = NextSeasonButton(embed=self.embed, tvshow=self.tvshow)
self.previous_season_button = PreviousSeasonButton(embed=self.embed, tvshow=self.tvshow)
embed = discord.Embed(title=f"{self.tvshow.title}", url=f'{provider_url}?video_id={self.tvshow.imdb_id}&s={self.tvshow.season}&e={self.tvshow.episode}', color=discord.Color.blue())
view = View(timeout=None)
view.add_item(self.previous_season_button)
view.add_item(self.next_season_button)
view.add_item(self.previous_button)
view.add_item(self.next_button)
await thread.send(content=f'{self.tvshow.title} Season {self.tvshow.season} Episode {self.tvshow.episode}', embed=embed, view=view)
class SettingsView(discord.ui.View):
def __init__(self, interaction):
super().__init__()
self.interaction = interaction
self.movie_select = MovieSelect()
self.tv_select = TVSelect()
self.add_item(self.movie_select)
self.add_item(self.tv_select)
with open('settings.csv', 'r') as file:
csv_reader = csv.reader(file)
next(csv_reader)
try:
for row in csv_reader:
if row[0] == str(interaction.user.id):
self.movie_select.placeholder = 'Set movie response privacy (Currently: True)' if row[2] == 'True' else 'Set movie response privacy (Currently: False)'
self.tv_select.placeholder = 'Set TV show response privacy (Currently: True)' if row[1] == 'True' else 'Set TV show response privacy (Currently: False)'
else:
pass
except StopIteration:
pass
class MovieSelect(discord.ui.Select):
def __init__(self):
options = [
discord.SelectOption(label='True', value=True),
discord.SelectOption(label='False', value=False)
]
super().__init__(placeholder='Set movie response privacy', min_values=1, max_values=1, options=options)
async def callback(self, interaction):
with open('settings.csv', 'r') as file:
csv_reader = csv.reader(file)
rows = [row for row in csv_reader]
found_user = False
for row in rows[1:]:
if row[0] == str(interaction.user.id):
found_user = True
row[2] = str(self.values[0])
break
if not found_user:
rows.append([str(interaction.user.id), 'False', str(self.values[0])])
with open('settings.csv', 'w', newline='') as file:
csv_writer = csv.writer(file)
csv_writer.writerows(rows)
await interaction.response.edit_message(view=SettingsView(interaction))
class TVSelect(discord.ui.Select):
def __init__(self):
options = [
discord.SelectOption(label='True', value=True),
discord.SelectOption(label='False', value=False)
]
super().__init__(placeholder='Set TV show response privacy', min_values=1, max_values=1, options=options)
async def callback(self, interaction):
with open('settings.csv', 'r') as file:
csv_reader = csv.reader(file)
rows = [row for row in csv_reader]
found_user = False
for row in rows[1:]:
if row[0] == str(interaction.user.id):
found_user = True
row[1] = str(self.values[0])
break
if not found_user:
rows.append([str(interaction.user.id), str(self.values[0]), 'False'])
with open('settings.csv', 'w', newline='') as file:
csv_writer = csv.writer(file)
csv_writer.writerows(rows)
await interaction.response.edit_message(view=SettingsView(interaction))