mirror of
https://github.com/NohamR/TransmissionBot.git
synced 2025-05-24 14:22:00 +00:00
bug fix
When auto-updating `summary`, reactions were not being removed for listing types of transfers of which there were none. Now that's fixed. e.g. if the number of downloading transfers goes from 1 to zero, the downloading reaction will be removed the next time the output is updated.
This commit is contained in:
parent
60537b6be9
commit
2217e3688b
36
bot.py
36
bot.py
@ -18,7 +18,6 @@ import os
|
|||||||
from os.path import expanduser, join
|
from os.path import expanduser, join
|
||||||
import re
|
import re
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
|
||||||
import pytz
|
import pytz
|
||||||
import platform
|
import platform
|
||||||
import transmissionrpc
|
import transmissionrpc
|
||||||
@ -42,8 +41,8 @@ TSCLIENT_CONFIG={
|
|||||||
}
|
}
|
||||||
|
|
||||||
DRYRUN = False
|
DRYRUN = False
|
||||||
REPEAT_FREQ = 5 # time in seconds to wait between reprinting repeated commands (in addition to the time requred to delete old message(s) and add reactions)
|
REPEAT_FREQ = 2 # time in seconds to wait between reprinting repeated commands (in addition to the time requred to delete old message(s) and add reactions)
|
||||||
REPEAT_TIMEOUT = 1800 # time in seconds before a repeated command automatically stops
|
REPEAT_TIMEOUT = 3600 # time in seconds before a repeated command automatically stops
|
||||||
|
|
||||||
logging.basicConfig(format='%(asctime)s %(message)s',filename=join(expanduser("~"),'transmissionbot.log'))
|
logging.basicConfig(format='%(asctime)s %(message)s',filename=join(expanduser("~"),'transmissionbot.log'))
|
||||||
|
|
||||||
@ -611,11 +610,18 @@ async def summary(context, *, content="", repeat=False):
|
|||||||
|
|
||||||
if repeat:
|
if repeat:
|
||||||
msg = REPEAT_MSG_LIST[0]
|
msg = REPEAT_MSG_LIST[0]
|
||||||
|
if context.message.channel.last_message_id != msg.id:
|
||||||
|
await msg.delete()
|
||||||
|
msg = await context.message.channel.send(embed=summaryData[0])
|
||||||
|
REPEAT_MSG_LIST = [msg]
|
||||||
|
else:
|
||||||
await msg.edit(embed=summaryData[0])
|
await msg.edit(embed=summaryData[0])
|
||||||
else:
|
else:
|
||||||
msg = await context.message.channel.send(embed=summaryData[0])
|
msg = await context.message.channel.send(embed=summaryData[0])
|
||||||
|
|
||||||
msgRxns = [str(r.emoji) for r in msg.reactions]
|
# to get actual list of reactions, need to re-fetch the message from the server
|
||||||
|
cache_msg = await context.message.channel.fetch_message(msg.id)
|
||||||
|
msgRxns = [str(r.emoji) for r in cache_msg.reactions]
|
||||||
|
|
||||||
for i in stateEmoji[:2]:
|
for i in stateEmoji[:2]:
|
||||||
if i not in msgRxns:
|
if i not in msgRxns:
|
||||||
@ -635,6 +641,10 @@ async def summary(context, *, content="", repeat=False):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if str(reaction.emoji) in stateEmoji[2:] and str(reaction.emoji) not in ignoreEmoji:
|
if str(reaction.emoji) in stateEmoji[2:] and str(reaction.emoji) not in ignoreEmoji:
|
||||||
|
if repeat:
|
||||||
|
REPEAT_COMMAND = False
|
||||||
|
REPEAT_MSG_LIST = []
|
||||||
|
await context.message.channel.send("❎ Auto-update cancelled...")
|
||||||
await list_transfers(context, content=torStateFilters[str(reaction.emoji)])
|
await list_transfers(context, content=torStateFilters[str(reaction.emoji)])
|
||||||
elif str(reaction.emoji) == stateEmoji[0]:
|
elif str(reaction.emoji) == stateEmoji[0]:
|
||||||
await legend(context)
|
await legend(context)
|
||||||
@ -644,9 +654,8 @@ async def summary(context, *, content="", repeat=False):
|
|||||||
REPEAT_MSG_LIST = []
|
REPEAT_MSG_LIST = []
|
||||||
await context.message.channel.send("❎ Auto-update cancelled...")
|
await context.message.channel.send("❎ Auto-update cancelled...")
|
||||||
else:
|
else:
|
||||||
REPEAT_MSG_LIST = [msg]
|
|
||||||
await msg.clear_reaction('🔄')
|
await msg.clear_reaction('🔄')
|
||||||
await repeat_command(summary, context=context, content=content)
|
await repeat_command(summary, context=context, content=content, msg_list=[msg])
|
||||||
|
|
||||||
def strListToList(strList):
|
def strListToList(strList):
|
||||||
if not re.match('^[0-9\,\-]+$', strList):
|
if not re.match('^[0-9\,\-]+$', strList):
|
||||||
@ -756,9 +765,13 @@ def torGetListOpsFromStr(listOpStr):
|
|||||||
|
|
||||||
return filter_by, sort_by, filter_regex
|
return filter_by, sort_by, filter_regex
|
||||||
|
|
||||||
async def repeat_command(command, context, content=""):
|
async def repeat_command(command, context, content="", msg_list=[]):
|
||||||
global REPEAT_COMMAND, REPEAT_MSG_LIST
|
global REPEAT_COMMAND, REPEAT_MSG_LIST
|
||||||
|
if REPEAT_COMMAND:
|
||||||
|
await context.message.channel.send("❎ Can't start auto-update when another command is already auto-updating...")
|
||||||
|
return
|
||||||
REPEAT_COMMAND = True
|
REPEAT_COMMAND = True
|
||||||
|
REPEAT_MSG_LIST = msg_list
|
||||||
start_time = datetime.datetime.now()
|
start_time = datetime.datetime.now()
|
||||||
while REPEAT_COMMAND:
|
while REPEAT_COMMAND:
|
||||||
delta = datetime.datetime.now() - start_time
|
delta = datetime.datetime.now() - start_time
|
||||||
@ -795,6 +808,10 @@ async def list_transfers(context, *, content="", repeat=False):
|
|||||||
|
|
||||||
if repeat:
|
if repeat:
|
||||||
msgs = REPEAT_MSG_LIST
|
msgs = REPEAT_MSG_LIST
|
||||||
|
if context.message.channel.last_message_id != msgs[-1].id:
|
||||||
|
for m in msgs:
|
||||||
|
await m.delete()
|
||||||
|
msgs = []
|
||||||
for i,e in enumerate(embeds):
|
for i,e in enumerate(embeds):
|
||||||
if i < len(msgs):
|
if i < len(msgs):
|
||||||
await msgs[i].edit(embed=e)
|
await msgs[i].edit(embed=e)
|
||||||
@ -840,9 +857,8 @@ async def list_transfers(context, *, content="", repeat=False):
|
|||||||
REPEAT_MSG_LIST = []
|
REPEAT_MSG_LIST = []
|
||||||
await context.message.channel.send("❎ Auto-update cancelled...")
|
await context.message.channel.send("❎ Auto-update cancelled...")
|
||||||
else:
|
else:
|
||||||
REPEAT_MSG_LIST = msgs
|
|
||||||
await msg.clear_reaction('🔄')
|
await msg.clear_reaction('🔄')
|
||||||
await repeat_command(list_transfers, context=context, content=content)
|
await repeat_command(list_transfers, context=context, content=content, msg_list=msgs)
|
||||||
|
|
||||||
@client.command(name='modify', aliases=['m'], pass_context=True)
|
@client.command(name='modify', aliases=['m'], pass_context=True)
|
||||||
async def modify(context, *, content=""):
|
async def modify(context, *, content=""):
|
||||||
@ -960,6 +976,8 @@ async def legend(context):
|
|||||||
embed.add_field(name="Tracker", value="🔒—private\n🔓—public", inline=True)
|
embed.add_field(name="Tracker", value="🔒—private\n🔓—public", inline=True)
|
||||||
embed.add_field(name="Modifications", value="⏸—pause\n▶️—resume\n❌—remove\n🗑—remove and delete\n🩺—verify", inline=True)
|
embed.add_field(name="Modifications", value="⏸—pause\n▶️—resume\n❌—remove\n🗑—remove and delete\n🩺—verify", inline=True)
|
||||||
await context.message.channel.send(embed=embed)
|
await context.message.channel.send(embed=embed)
|
||||||
|
if REPEAT_COMMAND:
|
||||||
|
await asyncio.sleep(5)
|
||||||
return
|
return
|
||||||
|
|
||||||
client.remove_command('help')
|
client.remove_command('help')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user