-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·160 lines (129 loc) · 4.31 KB
/
main.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
158
159
160
import re
import os
import discord
from utils import pattern_matcher, regex_strings
from constants import Site, url_regex
from embed_messages.SH_Embed import ScribbleHubEmbed
from embed_messages.AO3_Embed import ao3_main
from embed_messages.FF_Embed import FanFictionDotNetEmbed
from embed_messages.FL_Embed import FictionDotLiveEmbed
from embed_messages.WN_Embed import WebNovelEmbed
from embed_messages.SB_Embed import SpaceBattlesEmbed
from dotenv import load_dotenv
from keep_alive import keep_alive
load_dotenv()
BOT_TOKEN = os.getenv("TOKEN")
description = """A discord bot that scrapes metadata from certain sites."""
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
bot = discord.Bot(
description=description, intents=intents, debug_guilds=[916010209221177385]
)
# bot = commands.Bot(command_prefix=commands.when_mentioned_or("!"))
@bot.event
async def on_ready():
print(f"Logged in as {bot.user} (ID: {bot.user.id})")
print("____________________________________________")
@bot.event
async def on_message(message):
if message.author.id == bot.user.id:
return
if message.author.bot:
return # Do not reply to other bots
# Pulling out all URLs
urls = re.findall(
url_regex,
message.content,
re.VERBOSE,
)
for i in urls:
if pattern_matcher(regex_strings(Site.ScribbleHub), i):
await message.reply(embed=ScribbleHubEmbed(i))
elif pattern_matcher(regex_strings(Site.ArchiveOfOurOwn), i):
await message.reply(embed=ao3_main(i))
elif pattern_matcher(regex_strings(Site.FanFictionDotNet), i):
await message.reply(
file=FanFictionDotNetEmbed(i)[0], embed=FanFictionDotNetEmbed(i)[1]
)
elif pattern_matcher(regex_strings(Site.FictionLive), i):
await message.reply(embed=FictionDotLiveEmbed(i))
elif pattern_matcher(regex_strings(Site.WebNovel), i):
await message.reply(embed=WebNovelEmbed(i))
elif pattern_matcher(regex_strings(Site.SpaceBattles), i):
await message.reply(embed=SpaceBattlesEmbed(i))
# Slash Commands
# ScribbleHub
@bot.command(
name="scribble_hub", description="Gets ScribbleHub Stories or Profiles metadata"
)
async def scribble_hub(
ctx,
sh_url: discord.Option(
input_type=str,
description="The ScribbleHub Stories/Profiles URL",
required=True,
),
):
await ctx.defer()
await ctx.respond(embed=ScribbleHubEmbed(sh_url))
# ArchiveOfOurOwn
@bot.command(
name="archive_of_our_own",
description="Gets ArchiveOfOurOwn story/series/collection metadata",
)
async def archive_of_our_own(
ctx,
ao3_url: discord.Option(
input_type=str,
description="The ArchiveOfOurOwn story/series/collection URL",
required=True,
),
):
await ctx.defer()
await ctx.respond(embed=ao3_main(ao3_url))
# FanFiction.net
@bot.command(name="fanfiction_dotnet", description="Gets FanFiction.Net story metadata")
async def fanfiction_dotnet(
ctx,
ff_url: discord.Option(
input_type=str, description="The FanFiction.Net story URL", required=True
),
):
await ctx.defer()
await ctx.respond(
file=FanFictionDotNetEmbed(ff_url)[0], embed=FanFictionDotNetEmbed(ff_url)[1]
)
# Fiction.live
@bot.command(name="fiction_dot_live", description="Gets Fiction.Live story metadata")
async def fiction_dot_live(
ctx,
fl_url: discord.Option(
input_type=str, description="The Fiction.Live story URL", required=True
),
):
await ctx.defer()
await ctx.respond(embed=FictionDotLiveEmbed(fl_url))
# WebNovel
@bot.command(name="webnovel", description="Gets WebNovel story metadata")
async def webnovel(
ctx,
wn_url: discord.Option(
input_type=str, description="The WebNovel story URL", required=True
),
):
await ctx.defer()
await ctx.respond(embed=WebNovelEmbed(wn_url))
# SpaceBattles
@bot.command(name="space_battles", description="Gets SpaceBattles story metadata")
async def space_battles(
ctx,
sb_url: discord.Option(
input_type=str, description="The SpaceBattles story URL", required=True
),
):
await ctx.defer()
await ctx.respond(embed=SpaceBattlesEmbed(sb_url))
if __name__ == "__main__":
keep_alive()
bot.run(BOT_TOKEN)