From 27d3077f1456ae87eb77c0deb0e804cca1e2d8c8 Mon Sep 17 00:00:00 2001 From: Corban-Lee <77944149+Corban-Lee@users.noreply.github.com> Date: Tue, 11 Jul 2023 10:52:43 +0100 Subject: [PATCH] database and articleview changes --- .gitignore | 4 ++++ db/build.sql | 42 ----------------------------------------- db/db.sqlite | Bin 20480 -> 0 bytes src/db/db.py | 7 +++---- src/extensions/news.py | 31 ++++++++++++++++++++++++++---- 5 files changed, 34 insertions(+), 50 deletions(-) delete mode 100644 db/build.sql delete mode 100644 db/db.sqlite diff --git a/.gitignore b/.gitignore index 0e26039..5d1d7d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,10 @@ # Stores the Bot token TOKEN +# Databases +*.sqlite +*.db + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/db/build.sql b/db/build.sql deleted file mode 100644 index ffe3f2f..0000000 --- a/db/build.sql +++ /dev/null @@ -1,42 +0,0 @@ - -/* - Server Channels -*/ -CREATE TABLE IF NOT EXISTS 'server_channels' ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - channel_id INTEGER NOT NULL, - news_category_id INTEGER NOT NULL, - active INTEGER NOT NULL, - FOREIGN KEY (news_category_id) REFERENCES 'news_categories' (id) - ON DELETE CASCADE -); - - -/* - News Articles -*/ -CREATE TABLE IF NOT EXISTS 'news_articles' ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - url TEXT NOT NULL, - server_channel_id INTEGER NOT NULL, - FOREIGN KEY (server_channel_id) REFERENCES 'server_channels' (id) - ON DELETE CASCADE -); - - -/* - News Categories -*/ -CREATE TABLE IF NOT EXISTS 'news_categories' ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - name TEXT UNIQUE NOT NULL -); -INSERT OR IGNORE INTO 'news_categories' (name) VALUES ('all'); -INSERT OR IGNORE INTO 'news_categories' (name) VALUES ('world'); -INSERT OR IGNORE INTO 'news_categories' (name) VALUES ('uk'); -INSERT OR IGNORE INTO 'news_categories' (name) VALUES ('north_america'); -INSERT OR IGNORE INTO 'news_categories' (name) VALUES ('entertainment'); -INSERT OR IGNORE INTO 'news_categories' (name) VALUES ('business'); -INSERT OR IGNORE INTO 'news_categories' (name) VALUES ('tech'); -INSERT OR IGNORE INTO 'news_categories' (name) VALUES ('science'); -INSERT OR IGNORE INTO 'news_categories' (name) VALUES ('top_stories'); diff --git a/db/db.sqlite b/db/db.sqlite deleted file mode 100644 index c8dfd5f9de2afa587db03400eb78ae2a2d8442b7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20480 zcmeI(&u`mg7zgn8&6_xJw&ra$Z4s)5UTKInDs5>eMnP1Y7v8m2Q)jgurkyOuF`L!= z*kWgaV>FIj*qO_?!x8=f#+}Rf1GvBmt{^dq*P&ILtR1HwCVgMY$@@NU{Kn76zC6-v zXRj6|q4>1d@A!$hN@fYAo6VOO7U<*o#Ba94Za9oRzn?@wJB%j=xvDJ< zR|?m-S(9R7N-P%js3lCxm0QvlR^1g=qgH!I6!k&BEj}^q>b5Z%kHh|>uxoLcg14Vs-!F4s@u}sveMY%ORH3bEpJI%T2<+Y$=P_kLa{P>Gm|eb zEzwbYlyKlD;k{lzI!O6w$X-tRXz~?lcl}OyV%{fZ)UeFGh7^nGNtI${lWFC>B}$@h zEBq{e*j5#-=MR$JcH`e|5P$##AOHafKmY;|fB*y_ z0D;#+;8I2-nx^Ze{eL!|X5am&wEv?1{0p*viB83TjqiNhAv6d;00Izz00bZa0SG_<0uX=z1kOsJq%(5Gt>5+>w{Dx#DHa%+cdBN( zK_j1M(+9e<*B1N?bb31VFcKmY;|fB*y_ z009U<00Izz00h))_v{KiR{!hg*gQR`{|g0nk*4*3{ye)(59@zzjxErM`ahROChGsJ z#^z{ahv}?L$Mt_kV;6K)|NpoDe}nL^`3CeM009U<00Izz00bZa0SG_<0uY!KXl8O` z^uBgKNgl)>uC5M;! discord.TextChannel: """ @@ -229,10 +251,11 @@ class NewsCog(commands.Cog): return story_embed = await self.story_to_embed(story, category.name) + story_view = ArticleView(story) for channel in server_channels: - await send_or_ignore(channel.channel_id, story_embed, story.link) + await send_or_ignore(channel.channel_id, story_embed, story_view, story.link) - async def send_or_ignore(channel_id: int, story_embed: discord.Embed, story_link: str): + async def send_or_ignore(channel_id: int, story_embed: discord.Embed, story_view: ArticleView, story_link: str): """ Send (or don't) the given `story_embed` to a discord channel with the matching `channel_id`. The embed will be sent if a matching `story_link` has not already been sent to the channel. @@ -246,7 +269,7 @@ class NewsCog(commands.Cog): await flag_url_as_sent(channel_id, story_link) channel = await self._get_or_fetch_channel(channel_id) - await channel.send(embed=story_embed) + await channel.send(embed=story_embed, view=story_view) async def flag_url_as_sent(channel_id: int, story_link: str): """