Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #25

Closed
wants to merge 19 commits into from
Prev Previous commit
Fixed Archive
  • Loading branch information
MujyKun committed Dec 30, 2020
commit e35a3eb75df6c4b5d7ef6d85e4497106fa76e751
21 changes: 10 additions & 11 deletions module/Archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def check(m):
all_channels = await ex.conn.fetch("SELECT id, channelid, guildid, driveid, name FROM archive.channellist")
for p_id, channel_id, guild_id, drive_id, name in all_channels:
if message.channel.id != channel_id:
return None
return
if len(message.attachments):
for file in message.attachments:
url = file.url
Expand Down Expand Up @@ -62,7 +62,7 @@ def check(m):

@commands.has_guild_permissions(manage_messages=True)
@commands.command()
async def addchannel(self, ctx, drive_folder_id, name="NULL", owner_present=False):
async def addchannel(self, ctx, drive_folder_id, name="NULL", owner_present=0):
"""REQUIRES BOT OWNER PRESENCE -- Make the current channel start archiving images to google drive [Format: %addchannel <drive folder id> <optional - name>]"""
try:
if not owner_present:
Expand All @@ -73,12 +73,12 @@ async def addchannel(self, ctx, drive_folder_id, name="NULL", owner_present=Fals
if not await self.on_message(ctx, is_owner=True):
return await ctx.send("> **The bot owner did not confirm in time.**")

drive_id_in_db = ex.first_result(await ex.conn.fetchrow("SELECT COUNT(*) FROM archive.ChannelList WHERE DriveID = $1", drive_folder_id))
drive_id_in_db = ex.first_result(await ex.conn.fetchrow("SELECT COUNT(*) FROM archive.channellist WHERE driveid = $1", drive_folder_id))
if not drive_id_in_db:
url = f"https://drive.google.com/drive/folders/{drive_folder_id}"
return await ctx.send(f"> **{url} is already being used.**")

channel_id_in_db = ex.first_result(await ex.conn.fetchrow("SELECT COUNT(*) FROM archive.ChannelList WHERE ChannelID = $1", ctx.channel.id))
channel_id_in_db = ex.first_result(await ex.conn.fetchrow("SELECT COUNT(*) FROM archive.channellist WHERE channelid = $1", ctx.channel.id))
if not channel_id_in_db:
await ctx.send("> **This channel is already being archived**")

Expand All @@ -97,7 +97,6 @@ async def addchannel(self, ctx, drive_folder_id, name="NULL", owner_present=Fals
except Exception as e:
log.console(e)
await ctx.send("> **There was an error.**")
pass

# noinspection PyBroadException
@commands.has_guild_permissions(manage_messages=True)
Expand Down Expand Up @@ -134,9 +133,9 @@ async def deletechannel(self, ctx):
try:
channel_id_in_db = ex.first_result(await ex.conn.fetchrow("SELECT COUNT(*) FROM archive.ChannelList WHERE ChannelID = $1", ctx.channel.id))
if not channel_id_in_db:
await ctx.send("> **This channel is not currently being archived.**")
return await ctx.send("> **This channel is not currently being archived.**")
else:
await ex.conn.execute("DELETE FROM archive.ChannelList WHERE ChannelID = $1", ctx.channel.id)
await ex.conn.execute("DELETE FROM archive.channellist WHERE ChannelID = $1", ctx.channel.id)
await ctx.send("> **This channel is no longer being archived**")
except Exception as e:
log.console(e)
Expand All @@ -147,17 +146,17 @@ async def download_url(url, drive_id, channel_id):
try:
async with ex.session.get(url) as r:
if r.status != 200:
return None
return

check = False
unique_id = randint(0, 1000000000000)
unique_id2 = randint(0, 1000)
unique_id3 = randint(0, 500)
src = url[len(url)-4:len(url)]
checkerx = url.find(":large")
if checkerx != -1:
checker_x = url.find(":large")
if checker_x != -1:
src = url[len(url)-10:len(url)-6]
url = f"{url[0:checkerx-1]}:orig"
url = f"{url[0:checker_x-1]}:orig"

src2 = url.find('?format=')
if src2 != -1:
Expand Down