async def subscribe(self, ctx, subscriber, artist, mark=""): if self.managerCheck(ctx): subscriber = subscriber.mention.replace("!", "") if SQL_getData("artists", "artist", artist): await ctx.send(f"繪師 `{artist}` 已有訂閱紀錄", delete_after=5) # 已訂閱繪師 elif not SQL_getData("subscribers", "subscriber", subscriber): await ctx.send(f"{subscriber} 不在訂閱者名單內", delete_after=5) # 無此訂閱者 else: msg = await ctx.send(f"請確認 {subscriber} 訂閱 `{artist}`") if not await self.actionCheck(msg, ctx.author): await ctx.send("新增資料取消", delete_after=5) else: lastUpdate = str(get_date()) if mark: mark = f"({mark})" query = f"""INSERT INTO artists(artist, subscriber, "lastUpdateTime", mark) VALUES('{artist}', '{subscriber}', '{lastUpdate}', '{mark}')""" else: query = f"INSERT INTO artists(artist, subscriber, \"lastUpdateTime\") VALUES('{artist}', '{subscriber}', '{lastUpdate}')" message = f"訂閱紀錄:{subscriber} 訂閱了 `{artist}`(by{ctx.author.mention})" await self.changeData(ctx, query, message) else: await ctx.send("沒有權限或頻道錯誤", hidden=True)
async def delete_subscriber(self, ctx, subscriber): if self.managerCheck(ctx): await ctx.defer() subscriber = subscriber.mention.replace("!", "") if SQL_getData("subscribers", "subscriber", subscriber): artists = SQL_getData("artists", "subscriber", subscriber) message = f"請確認刪除 {subscriber} 的資料" if len(artists) != 0: message += ",***以下繪師資料也將被刪除***:" for artist in artists: # 列出目標訂閱的繪師 message += f"`{artist[0]}`" if artist != artists[-1]: message += "、" msg = await ctx.send(message) if await self.actionCheck(msg, ctx.author): query = f'DELETE FROM subscribers WHERE subscriber="{subscriber}"' message = f"訂閱紀錄:{ctx.author.mention} 刪除了 {subscriber} 的資料" await self.changeData(ctx, query, message) else: await ctx.send("刪除訂閱者資料取消", delete_after=5) else: await ctx.send(f"{subscriber} 不在訂閱者名單內", hidden=True) else: await ctx.send("沒有權限或頻道錯誤", hidden=True)
async def edit_url(self, ctx, item, url, subscriber: discord.Member = None): # item:0->預覽,1->下載 if subscriber is None: subscriber = ctx.author.mention.replace("!", "") else: subscriber = subscriber.mention.replace("!", "") if url == "None": url = None # 刪除網址 else: url = url.split(" ") url = "\n".join(url) if "\n" in url: url = "\n" + url if self.authorCheck(ctx, subscriber): if not SQL_getData("subscribers", "subscriber", subscriber, 1): await ctx.send(f"{subscriber} 不在訂閱者名單內", delete_after=5) else: query = f"UPDATE subscribers SET {item}='{url}' WHERE subscriber='{subscriber}'" if await self.changeData(ctx, query): await ctx.send("更改成功", hidden=True) else: await ctx.send("沒有權限或頻道錯誤", hidden=True)
async def change_subscriber(self, ctx, artist, newsubscriber): if self.managerCheck(ctx): newsubscriber = newsubscriber.mention.replace("!", "") artist = SQL_getData("artists", "artist", artist, 1) if SQL_getData("subscribers", "subscriber", newsubscriber) and artist: if artist[1] == newsubscriber: # 原訂閱者和新訂閱者相同 await ctx.send("原訂閱者和新訂閱者相同", delete_after=5) else: msg = await ctx.send( f"請確認 `{artist[0]}` 由 {artist[1]} 改為 {newsubscriber} 訂閱" ) if not await self.actionCheck(msg, ctx.author): await ctx.send("更改訂閱者取消", delete_after=5) else: query = f"UPDATE artists SET subscriber='{newsubscriber}' WHERE artist='{artist[0]}'" message = f"訂閱紀錄:{ctx.author.mention} 將 `{artist[0]}` 由 {artist[1]} 改為 {newsubscriber} 訂閱" await self.changeData(ctx, query, message) else: await ctx.send("新訂閱者不在訂閱者名單內或繪師尚未被訂閱", delete_after=5) else: await ctx.send("沒有權限或頻道錯誤", hidden=True)
async def unsubscribe(self, ctx, artist): if self.managerCheck(ctx): artist = SQL_getData("artists", "artist", artist, 1) # (artist, subscriber, ...) if artist: msg = await ctx.send(f"請確認 {artist[1]} 取消訂閱 `{artist[0]}`") if not await self.actionCheck(msg, ctx.author): await ctx.send("刪除資料取消", delete_after=5) else: query = f"DELETE FROM artists WHERE artist='{artist[0]}'" message = f"訂閱紀錄:{artist[1]} 取消訂閱 `{artist[0]}`(by {ctx.author.mention})" await self.changeData(ctx, query, message) else: await ctx.send(f"無人訂閱 {artist[0]}", delete_after=5) else: await ctx.send("沒有權限或頻道錯誤", hidden=True)
async def get_user(self, ctx): await ctx.message.delete() if ctx.channel.id in CHANNELS and ctx.message.reference: if REDIS.sismember("msg_ids", ctx.message.reference.message_id): users = SQL_getData( "user_record", "msg_id", ctx.message.reference.message_id) # ((msg_id, user_id)) if users: users = "\n".join(set(map(lambda x: x[1], users))) await ctx.author.send(f"取得過該連結的使用者紀錄:\n{users}") else: await ctx.author.send("無人取得過該連結") else: await ctx.send("該訊息尚未建檔,因此無取得連結的使用者紀錄") else: await ctx.send("頻道錯誤或沒有指定(reply)訊息")
async def on_raw_reaction_add(self, payload): if payload.channel_id in CHANNELS and not (payload.member.bot): if REDIS.sismember( "msg_ids", payload.message_id) and payload.emoji.id == EMOJI_ID: url = SQL_getData("book_url", "msg_id", payload.message_id, 1)[1] try: await payload.member.send(url) except: await self.bot.get_channel(payload.channel_id).send( payload.member.mention + "無法私訊連結給你,請檢查私訊設定", delete_after=7) else: try: SQL_modify( f"INSERT INTO user_record VALUES('{payload.message_id}', '<@{payload.user_id}>')" ) except: pass
async def upload(self, ctx, artist="", subscriber=""): if subscriber != "": subscriber = subscriber.mention.replace("!", "") # 有指定訂閱者 else: subscriber = ctx.author.mention.replace("!", "") if self.authorCheck(ctx, subscriber): subscriber = SQL_getData("subscribers", "subscriber", subscriber, 1) if subscriber: if not artist: await ctx.send( f"{subscriber[0]} 上傳了圖包\n>>> 下載網址:\n{subscriber[2]}" ) # 有填寫繪師名稱 else: await ctx.send( f"{subscriber[0]} 上傳了 `{artist}` 的圖包\n>>> 下載網址:\n{subscriber[2]}" ) else: await ctx.send("訂閱者名單中沒有 {subscriber[0]} 這個人", delete_after=3) else: await ctx.send("沒有權限或頻道錯誤", hidden=True)
async def new_subscriber(self, ctx, subscriber, download_url, preview_url=None): if self.managerCheck(ctx): await ctx.defer() subscriber = subscriber.mention.replace("!", "") if SQL_getData("subscribers", "subscriber", subscriber): await ctx.send(f"{subscriber} 已在訂閱者名單", hidden=True) else: download_url = download_url.replace(" ", "\n") if preview_url is not None: # 有預覽網址 preview_url = preview_url.replace(" ", "\n") else: # 無預覽網址 preview_url = "無" query = f"""INSERT INTO subscribers(subscriber, preview_url, download_url) VALUES('{subscriber}', '{preview_url}', '{download_url}')""" message = f"新訂閱者:{subscriber}(by {ctx.author.mention})" await self.changeData(ctx, query, message) else: await ctx.send("沒有權限或頻道錯誤", hidden=True)