From dd0dbb0f27862fea5710976ebef9cebfc2e3571a Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 11:13:56 -0400 Subject: [PATCH 01/88] formatting --- bot_config.conf.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot_config.conf.example b/bot_config.conf.example index 81014cf..af77115 100644 --- a/bot_config.conf.example +++ b/bot_config.conf.example @@ -12,7 +12,7 @@ # statping_api_key - API Key for Statping to query for service status # discord_auth_token = -bot_command_prefix= +bot_command_prefix = hass_url = hass_token = hass_light = -- 2.39.5 From 2ef6cf60539a236f9ea786f4aad42da6348a42c1 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 14:54:35 -0400 Subject: [PATCH 02/88] Added new test functions to read in spsubs from file --- r0b3bot.py | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 115 insertions(+), 5 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 04f315b..0f95bee 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -16,6 +16,7 @@ from discord.utils import get from discord.voice_client import VoiceClient import requests import asyncio +import pickle #Record the time the bot started @@ -28,9 +29,6 @@ configFilePath = r'bot_config.conf' global last_error last_error = "No errors have been recorded." -global spsublist -spsublist = [] - try: config.read(configFilePath) except: @@ -84,6 +82,9 @@ async def on_ready(): activity = discord.Activity(name="your $commands",type=discord.ActivityType.listening) await bot.change_presence(activity=activity) + #Run StatPing_Monitor + await StatPing_Monitor() + @bot.command() async def greetings(ctx): await ctx.send(":smiley: :wave: Hello there!") @@ -599,7 +600,115 @@ async def spsub(ctx, service = "NONE"): print(f"'{service}' does not exist, cancelling subscription") await ctx.send(f"{service} was not found") -async def sp_monitor(spsublist): +@bot.command() +async def spsub_T(ctx, service = "NONE"): + + spsublist = [] + currentsub_request = [] + datestring = datetime.now() + datestring = datestring.strftime("%m/%d/%Y-%H:%M:%S") + print(f"[{datestring}]: {ctx.message.author.display_name} called '$spsub {service}'") + + if service != "NONE": + + print(f">> Querying status of '{service}' to see if it exists") + service_state = await get_stp_status(service) + + if service_state != "service not found": + + print(f">> '{service}' exists, adding to StatPing Monitor") + await ctx.send(f"'{service_state['name']}' added to monitored services") + currentsub_request.append(ctx) + currentsub_request.append(service) + currentsub_request.append("online") + + # read in data file containing list of subscriptions + print(">> Reading in spsublist.dat") + if os.path.exists('spsublist.dat'): + with open('spsublist.dat', 'rb') as datafile: + spsublist = pickle.load(datafile) + else: + print(">> spsublist.dat does not exist, new file will be created") + + # append new subscription to array + print(">> Appending new sub to array") + spsublist.append(currentsub_request) + + #Write updated array to data file + print(">> Writing updated array to spsublist.dat") + with open('spsublist.dat', 'wb') as datafile: + pickle.dump(spsublist, datafile) + + print(">> Done") + await ctx.send(f"'{service_state['name']}' added to monitored services") + + #await sp_monitor(currentsub_request) + + else: + print(f">> '{service}' does not exist, cancelling subscription") + await ctx.send(f"{service} was not found") + +async def StatPing_Monitor(): + + # reads in "spsublist.dat" every 60 seconds then iterates + # through to check for service status changes. This function will need to check + # that "spsublist.dat" exists and is not empty. This function should be called + # in bot.on_ready + + new_spsublist = [] + + # read in data file containing list of subscriptions + while True: + print("Statping Monitor: Reading in spsublist.dat") + if os.path.exists('spsublist.dat'): + with open('spsublist.dat', 'rb') as datafile: + spsublist = pickle.load(datafile) + + for subscription in spsublist: + + ctx = subscription[0] + status = await get_stp_status(subscription[1]) + + if status['online'] and subscription[2] == "online": + + # nothing has changed, no alert needed + await asyncio.sleep(1) + elif not status['online'] and subscription[2] == "offline": + + # again, nothing has changed no alert needed + await asyncio.sleep(1) + else: + print(f"Status of {status['name']}' has changed") + if status['online']: + + embed = discord.Embed(title=f"Service Alert", description=f"{status['name']} is Online!", color=0x00ff40) + await ctx.send(embed=embed) + subscription[2] = "online" + + elif not status['online']: + + embed = discord.Embed(title=f"Service Alert", description=f"{status['name']} is Offline!", color=0xff2200) + await ctx.send(embed=embed) + subscription[2] = "offline" + + else: + + embed = discord.Embed(title=f"Service Alert", description=f"{status['name']} is in an unknown state!", color=0xffff00) + await ctx.send(embed=embed) + + new_spsublist.append(subscription) + + # Write status changes to spsublist.dat + with open('spsublist.dat', 'w') as datafile: + pickle.dump(new_spsublist, datafile) + + else: + print(">> spsublist.dat does not exist, nothing to do.") + + await asyncio.sleep(60) + + +async def sp_monitor(sublist): # Checks the services listed in spsublist for status change # Sublist is a list of 3 items: @@ -607,7 +716,8 @@ async def sp_monitor(spsublist): # - service (the name of the service to check) # - status string (last status of the service, either 'online' or 'offline') - ctx = spsublist[0] + ctx = sublist[0] + while True: -- 2.39.5 From 142a7fcf48cfa9380eb644bb3d130cf1cffc3fc6 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 14:59:07 -0400 Subject: [PATCH 03/88] forgot awaits --- r0b3bot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 0f95bee..d1cd6c1 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -626,7 +626,7 @@ async def spsub_T(ctx, service = "NONE"): print(">> Reading in spsublist.dat") if os.path.exists('spsublist.dat'): with open('spsublist.dat', 'rb') as datafile: - spsublist = pickle.load(datafile) + spsublist = await pickle.load(datafile) else: print(">> spsublist.dat does not exist, new file will be created") @@ -637,7 +637,7 @@ async def spsub_T(ctx, service = "NONE"): #Write updated array to data file print(">> Writing updated array to spsublist.dat") with open('spsublist.dat', 'wb') as datafile: - pickle.dump(spsublist, datafile) + await pickle.dump(spsublist, datafile) print(">> Done") await ctx.send(f"'{service_state['name']}' added to monitored services") @@ -662,7 +662,7 @@ async def StatPing_Monitor(): print("Statping Monitor: Reading in spsublist.dat") if os.path.exists('spsublist.dat'): with open('spsublist.dat', 'rb') as datafile: - spsublist = pickle.load(datafile) + spsublist = await pickle.load(datafile) for subscription in spsublist: @@ -700,7 +700,7 @@ async def StatPing_Monitor(): # Write status changes to spsublist.dat with open('spsublist.dat', 'w') as datafile: - pickle.dump(new_spsublist, datafile) + await pickle.dump(new_spsublist, datafile) else: print(">> spsublist.dat does not exist, nothing to do.") -- 2.39.5 From 0f607f67ee405f4ed9b8b4c183edaf5b04736550 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 15:04:55 -0400 Subject: [PATCH 04/88] more awaits? --- r0b3bot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index d1cd6c1..81ceeff 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -625,7 +625,7 @@ async def spsub_T(ctx, service = "NONE"): # read in data file containing list of subscriptions print(">> Reading in spsublist.dat") if os.path.exists('spsublist.dat'): - with open('spsublist.dat', 'rb') as datafile: + await with open('spsublist.dat', 'rb') as datafile: spsublist = await pickle.load(datafile) else: print(">> spsublist.dat does not exist, new file will be created") @@ -636,7 +636,7 @@ async def spsub_T(ctx, service = "NONE"): #Write updated array to data file print(">> Writing updated array to spsublist.dat") - with open('spsublist.dat', 'wb') as datafile: + await with open('spsublist.dat', 'wb') as datafile: await pickle.dump(spsublist, datafile) print(">> Done") @@ -661,7 +661,7 @@ async def StatPing_Monitor(): while True: print("Statping Monitor: Reading in spsublist.dat") if os.path.exists('spsublist.dat'): - with open('spsublist.dat', 'rb') as datafile: + await with open('spsublist.dat', 'rb') as datafile: spsublist = await pickle.load(datafile) for subscription in spsublist: @@ -699,7 +699,7 @@ async def StatPing_Monitor(): new_spsublist.append(subscription) # Write status changes to spsublist.dat - with open('spsublist.dat', 'w') as datafile: + await with open('spsublist.dat', 'w') as datafile: await pickle.dump(new_spsublist, datafile) else: -- 2.39.5 From 7391e68778f2dfcc5d0a22a401de7f49d18d75cf Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 15:14:12 -0400 Subject: [PATCH 05/88] replace pickle with aiofile --- r0b3bot.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 81ceeff..3a64aa0 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -16,7 +16,7 @@ from discord.utils import get from discord.voice_client import VoiceClient import requests import asyncio -import pickle +from aiofile import AIOfile #Record the time the bot started @@ -625,8 +625,8 @@ async def spsub_T(ctx, service = "NONE"): # read in data file containing list of subscriptions print(">> Reading in spsublist.dat") if os.path.exists('spsublist.dat'): - await with open('spsublist.dat', 'rb') as datafile: - spsublist = await pickle.load(datafile) + async with AIOfile('spsublist.dat', 'rb') as datafile: + spsublist = await datafile.read() else: print(">> spsublist.dat does not exist, new file will be created") @@ -636,8 +636,9 @@ async def spsub_T(ctx, service = "NONE"): #Write updated array to data file print(">> Writing updated array to spsublist.dat") - await with open('spsublist.dat', 'wb') as datafile: - await pickle.dump(spsublist, datafile) + async with AIOfile('spsublist.dat', 'wb') as datafile: + await datafile.write(spsublist) + await datafile.fsync() print(">> Done") await ctx.send(f"'{service_state['name']}' added to monitored services") @@ -661,8 +662,8 @@ async def StatPing_Monitor(): while True: print("Statping Monitor: Reading in spsublist.dat") if os.path.exists('spsublist.dat'): - await with open('spsublist.dat', 'rb') as datafile: - spsublist = await pickle.load(datafile) + async with AIOfile('spsublist.dat', 'rb') as datafile: + spsublist = await datafile.read() for subscription in spsublist: @@ -699,8 +700,9 @@ async def StatPing_Monitor(): new_spsublist.append(subscription) # Write status changes to spsublist.dat - await with open('spsublist.dat', 'w') as datafile: - await pickle.dump(new_spsublist, datafile) + async with AIOfile('spsublist.dat', 'w') as datafile: + await datafile.write(new_spsublist) + await datafile.fsync() else: print(">> spsublist.dat does not exist, nothing to do.") -- 2.39.5 From ae601c45f53192300d78d50686f18e2ef156ffa8 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 15:15:52 -0400 Subject: [PATCH 06/88] typo --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 3a64aa0..6aeccb4 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -16,7 +16,7 @@ from discord.utils import get from discord.voice_client import VoiceClient import requests import asyncio -from aiofile import AIOfile +from aiofiles import AIOfile #Record the time the bot started -- 2.39.5 From 8d02152697c84e719831ae3ce9103d2bde65fbd7 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 15:16:54 -0400 Subject: [PATCH 07/88] more typo fixes --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 6aeccb4..bf5655a 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -16,7 +16,7 @@ from discord.utils import get from discord.voice_client import VoiceClient import requests import asyncio -from aiofiles import AIOfile +from aiofile import AIOFile #Record the time the bot started -- 2.39.5 From 5575dbb054492df4edebd95139f7aa66900c3076 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 15:18:45 -0400 Subject: [PATCH 08/88] case update --- r0b3bot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index bf5655a..9bacab2 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -625,7 +625,7 @@ async def spsub_T(ctx, service = "NONE"): # read in data file containing list of subscriptions print(">> Reading in spsublist.dat") if os.path.exists('spsublist.dat'): - async with AIOfile('spsublist.dat', 'rb') as datafile: + async with AIOFile('spsublist.dat', 'rb') as datafile: spsublist = await datafile.read() else: print(">> spsublist.dat does not exist, new file will be created") @@ -636,7 +636,7 @@ async def spsub_T(ctx, service = "NONE"): #Write updated array to data file print(">> Writing updated array to spsublist.dat") - async with AIOfile('spsublist.dat', 'wb') as datafile: + async with AIOFile('spsublist.dat', 'wb') as datafile: await datafile.write(spsublist) await datafile.fsync() @@ -662,7 +662,7 @@ async def StatPing_Monitor(): while True: print("Statping Monitor: Reading in spsublist.dat") if os.path.exists('spsublist.dat'): - async with AIOfile('spsublist.dat', 'rb') as datafile: + async with AIOFile('spsublist.dat', 'rb') as datafile: spsublist = await datafile.read() for subscription in spsublist: @@ -700,7 +700,7 @@ async def StatPing_Monitor(): new_spsublist.append(subscription) # Write status changes to spsublist.dat - async with AIOfile('spsublist.dat', 'w') as datafile: + async with AIOFile('spsublist.dat', 'w') as datafile: await datafile.write(new_spsublist) await datafile.fsync() -- 2.39.5 From ca06fea13f08af7761065166349f5b0d4c4222c6 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 15:28:06 -0400 Subject: [PATCH 09/88] trying different library --- r0b3bot.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 9bacab2..6a42d2b 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -17,6 +17,7 @@ from discord.voice_client import VoiceClient import requests import asyncio from aiofile import AIOFile +import aiofiles as aiof #Record the time the bot started @@ -625,7 +626,7 @@ async def spsub_T(ctx, service = "NONE"): # read in data file containing list of subscriptions print(">> Reading in spsublist.dat") if os.path.exists('spsublist.dat'): - async with AIOFile('spsublist.dat', 'rb') as datafile: + async with aiof.open('spsublist.dat', 'rb') as datafile: spsublist = await datafile.read() else: print(">> spsublist.dat does not exist, new file will be created") @@ -636,9 +637,10 @@ async def spsub_T(ctx, service = "NONE"): #Write updated array to data file print(">> Writing updated array to spsublist.dat") - async with AIOFile('spsublist.dat', 'wb') as datafile: + async with aiof.open('spsublist.dat', 'wb') as datafile: await datafile.write(spsublist) - await datafile.fsync() + #await datafile.fsync() + await datafile.flush() print(">> Done") await ctx.send(f"'{service_state['name']}' added to monitored services") @@ -662,7 +664,7 @@ async def StatPing_Monitor(): while True: print("Statping Monitor: Reading in spsublist.dat") if os.path.exists('spsublist.dat'): - async with AIOFile('spsublist.dat', 'rb') as datafile: + async with aiof.open('spsublist.dat', 'rb') as datafile: spsublist = await datafile.read() for subscription in spsublist: @@ -700,9 +702,10 @@ async def StatPing_Monitor(): new_spsublist.append(subscription) # Write status changes to spsublist.dat - async with AIOFile('spsublist.dat', 'w') as datafile: + async with aiof.open('spsublist.dat', 'w') as datafile: await datafile.write(new_spsublist) - await datafile.fsync() + #await datafile.fsync() + await datafile.flush() else: print(">> spsublist.dat does not exist, nothing to do.") -- 2.39.5 From 3832d13200067fc48494badf08b1e0784e8286a2 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 20:50:38 -0400 Subject: [PATCH 10/88] saving just channel id and now appending --- r0b3bot.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 6a42d2b..1e1226e 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -619,7 +619,9 @@ async def spsub_T(ctx, service = "NONE"): print(f">> '{service}' exists, adding to StatPing Monitor") await ctx.send(f"'{service_state['name']}' added to monitored services") - currentsub_request.append(ctx) + currentsub_request.append(ctx.message.channel) + print(f">> channel ID: {ctx.message.channel}") + #currentsub_request.append(ctx) currentsub_request.append(service) currentsub_request.append("online") @@ -637,7 +639,7 @@ async def spsub_T(ctx, service = "NONE"): #Write updated array to data file print(">> Writing updated array to spsublist.dat") - async with aiof.open('spsublist.dat', 'wb') as datafile: + async with aiof.open('spsublist.dat', 'a') as datafile: await datafile.write(spsublist) #await datafile.fsync() await datafile.flush() @@ -664,7 +666,7 @@ async def StatPing_Monitor(): while True: print("Statping Monitor: Reading in spsublist.dat") if os.path.exists('spsublist.dat'): - async with aiof.open('spsublist.dat', 'rb') as datafile: + async with aiof.open('spsublist.dat', 'r') as datafile: spsublist = await datafile.read() for subscription in spsublist: -- 2.39.5 From a95b88d99f1449ac1d30322e0515c353b2872cdc Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 20:52:14 -0400 Subject: [PATCH 11/88] no bytes --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 1e1226e..e2b11a6 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -628,7 +628,7 @@ async def spsub_T(ctx, service = "NONE"): # read in data file containing list of subscriptions print(">> Reading in spsublist.dat") if os.path.exists('spsublist.dat'): - async with aiof.open('spsublist.dat', 'rb') as datafile: + async with aiof.open('spsublist.dat', 'r') as datafile: spsublist = await datafile.read() else: print(">> spsublist.dat does not exist, new file will be created") -- 2.39.5 From 2970adc6340542a03083c90c61df01edd355ba8b Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 21:08:47 -0400 Subject: [PATCH 12/88] using pickle again --- r0b3bot.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index e2b11a6..92fe5c3 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -18,6 +18,7 @@ import requests import asyncio from aiofile import AIOFile import aiofiles as aiof +import pickle #Record the time the bot started @@ -628,8 +629,9 @@ async def spsub_T(ctx, service = "NONE"): # read in data file containing list of subscriptions print(">> Reading in spsublist.dat") if os.path.exists('spsublist.dat'): - async with aiof.open('spsublist.dat', 'r') as datafile: - spsublist = await datafile.read() + async with aiof.open('spsublist.dat', 'rb') as datafile: + pickled_spsublist = await datafile.read() + spsublist = pickle.loads(pickled_spsublist) else: print(">> spsublist.dat does not exist, new file will be created") @@ -639,7 +641,8 @@ async def spsub_T(ctx, service = "NONE"): #Write updated array to data file print(">> Writing updated array to spsublist.dat") - async with aiof.open('spsublist.dat', 'a') as datafile: + async with aiof.open('spsublist.dat', 'wb') as datafile: + pickled_spsublist = pickle.dumps(spsublist) await datafile.write(spsublist) #await datafile.fsync() await datafile.flush() @@ -666,8 +669,9 @@ async def StatPing_Monitor(): while True: print("Statping Monitor: Reading in spsublist.dat") if os.path.exists('spsublist.dat'): - async with aiof.open('spsublist.dat', 'r') as datafile: - spsublist = await datafile.read() + async with aiof.open('spsublist.dat', 'rb') as datafile: + pickled_spsublist = await datafile.read() + spsublist = pickle.loads(pickled_spsublist) for subscription in spsublist: @@ -704,7 +708,8 @@ async def StatPing_Monitor(): new_spsublist.append(subscription) # Write status changes to spsublist.dat - async with aiof.open('spsublist.dat', 'w') as datafile: + async with aiof.open('spsublist.dat', 'wb') as datafile: + pickled_spsublist = pickle.dumps(new_spsublist) await datafile.write(new_spsublist) #await datafile.fsync() await datafile.flush() -- 2.39.5 From 9af4a5292723332bd48da251bf2fe5396b793ba5 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 23:11:49 -0400 Subject: [PATCH 13/88] reqrote spsub_T to use/create a nested dictionary --- r0b3bot.py | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 92fe5c3..b4f0311 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -16,7 +16,7 @@ from discord.utils import get from discord.voice_client import VoiceClient import requests import asyncio -from aiofile import AIOFile +#from aiofile import AIOFile import aiofiles as aiof import pickle @@ -605,40 +605,71 @@ async def spsub(ctx, service = "NONE"): @bot.command() async def spsub_T(ctx, service = "NONE"): - spsublist = [] - currentsub_request = [] + spsublist = {} # Statping Subscription list to be read in from file + # Structure of spsublist nested dictionary + # spsublist[service name][list of channel ids][a state value] + # dict = {'Plex': {'state' : 'online', 'channels' : ['1232', '43234']} + # 'Space Eingineers' : {'state' : online', 'channels' : ['2343', '54563']}} + # + currentsub_request = [] # list of elements detailing the current sub request datestring = datetime.now() datestring = datestring.strftime("%m/%d/%Y-%H:%M:%S") + print(f"[{datestring}]: {ctx.message.author.display_name} called '$spsub {service}'") + # Only work on this if the user has supplied a service name to monitor, a value of NONE + # means nothing was specified. if service != "NONE": + # Verify that the service name requested acutally exists print(f">> Querying status of '{service}' to see if it exists") service_state = await get_stp_status(service) + # If the service exists, proceed with adding it to the list. if service_state != "service not found": print(f">> '{service}' exists, adding to StatPing Monitor") await ctx.send(f"'{service_state['name']}' added to monitored services") - currentsub_request.append(ctx.message.channel) + currentsub_request.append(ctx.message.channel.id) print(f">> channel ID: {ctx.message.channel}") #currentsub_request.append(ctx) - currentsub_request.append(service) + currentsub_request.append(service_state['name']) currentsub_request.append("online") - # read in data file containing list of subscriptions + # read in data file containing dict of subscriptions print(">> Reading in spsublist.dat") if os.path.exists('spsublist.dat'): + + # Read in spsublist async with aiof.open('spsublist.dat', 'rb') as datafile: pickled_spsublist = await datafile.read() spsublist = pickle.loads(pickled_spsublist) + + for service, info in spsublist.keys(): + # service = service_names + # info = dict of service information + + if service == currentsub_request[1]: + # This service matched what the user is trying to subscribe to + # Now we need to check if this is for the same channel + for channels in service['channels']: + if channel == currentsub_request[0]: + print(">> Subscribed Already") + else: + # Append the current channel id to the list for this service + print(f">> Appending {currentsub_request[1]} to {channel}") + spsublist[service]['channels'].append(currentsub_request[1]) + else: + print(">> spsublist.dat does not exist, new file will be created") - # append new subscription to array - print(">> Appending new sub to array") - spsublist.append(currentsub_request) - + # append new subscription to dict + print(">> Creating new dictionary") + + spsublist[currentsub_request[1]]['state'] = 'online' + spsublist[currentsub_request[1]]['channels'].append(currentsub_request[0]) + #Write updated array to data file print(">> Writing updated array to spsublist.dat") async with aiof.open('spsublist.dat', 'wb') as datafile: -- 2.39.5 From 077e82bda208cc9fbe9c81728a6cdc38f984eb6e Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 23:28:05 -0400 Subject: [PATCH 14/88] reworked StatPing_Montor to use dict --- r0b3bot.py | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index b4f0311..5f579bb 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -669,7 +669,7 @@ async def spsub_T(ctx, service = "NONE"): spsublist[currentsub_request[1]]['state'] = 'online' spsublist[currentsub_request[1]]['channels'].append(currentsub_request[0]) - + #Write updated array to data file print(">> Writing updated array to spsublist.dat") async with aiof.open('spsublist.dat', 'wb') as datafile: @@ -694,7 +694,7 @@ async def StatPing_Monitor(): # that "spsublist.dat" exists and is not empty. This function should be called # in bot.on_ready - new_spsublist = [] + #new_spsublist = {} # read in data file containing list of subscriptions while True: @@ -704,44 +704,49 @@ async def StatPing_Monitor(): pickled_spsublist = await datafile.read() spsublist = pickle.loads(pickled_spsublist) - for subscription in spsublist: + for service, info in spsublist: + # service used to be subscription - ctx = subscription[0] - status = await get_stp_status(subscription[1]) + status = await get_stp_status(service) - if status['online'] and subscription[2] == "online": + if status['online'] and service['state'] == "online": # nothing has changed, no alert needed await asyncio.sleep(1) - elif not status['online'] and subscription[2] == "offline": + elif not status['online'] and service['state'] == "offline": # again, nothing has changed no alert needed await asyncio.sleep(1) else: - print(f"Status of {status['name']}' has changed") + + print(f"Status of {service}' has changed, notifying subscribed channels") + if status['online']: - - embed = discord.Embed(title=f"Service Alert", description=f"{status['name']} is Online!", color=0x00ff40) - await ctx.send(embed=embed) - subscription[2] = "online" + for channel in service['channels']: + ctx = bot.get_channel(channel) + embed = discord.Embed(title=f"Service Alert", description=f"{service} is Online!", color=0x00ff40) + await ctx.send(embed=embed) + spsublist[service]['state'] = 'online' elif not status['online']: - - embed = discord.Embed(title=f"Service Alert", description=f"{status['name']} is Offline!", color=0xff2200) - await ctx.send(embed=embed) - subscription[2] = "offline" + for channel in service['channels']: + ctx = bot.get_channel(channel) + embed = discord.Embed(title=f"Service Alert", description=f"{service} is Offline!", color=0xff2200) + await ctx.send(embed=embed) + spsublist[service]['state'] = 'offline' else: - - embed = discord.Embed(title=f"Service Alert", description=f"{status['name']} is in an unknown state!", color=0xffff00) - await ctx.send(embed=embed) + for channel in service['channels']: + ctx = bot.get_channel(channel) + embed = discord.Embed(title=f"Service Alert", description=f"{service} is in an unknown state!", color=0xffff00) + await ctx.send(embed=embed) new_spsublist.append(subscription) # Write status changes to spsublist.dat async with aiof.open('spsublist.dat', 'wb') as datafile: - pickled_spsublist = pickle.dumps(new_spsublist) - await datafile.write(new_spsublist) + pickled_spsublist = pickle.dumps(spsublist) + await datafile.write(pickled_spsublist) #await datafile.fsync() await datafile.flush() -- 2.39.5 From 204acac19cb130f164c9c24c181b099b16c141fd Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 23:35:07 -0400 Subject: [PATCH 15/88] now adding key --- r0b3bot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/r0b3bot.py b/r0b3bot.py index 5f579bb..4457de6 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -667,6 +667,7 @@ async def spsub_T(ctx, service = "NONE"): # append new subscription to dict print(">> Creating new dictionary") + spsublist[currentsub_request[1]] = '' spsublist[currentsub_request[1]]['state'] = 'online' spsublist[currentsub_request[1]]['channels'].append(currentsub_request[0]) -- 2.39.5 From e08621d31784c4b3d7672ab34b98d6ffed6fc55d Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 23:38:09 -0400 Subject: [PATCH 16/88] saving pickled dict --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 4457de6..c687911 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -675,7 +675,7 @@ async def spsub_T(ctx, service = "NONE"): print(">> Writing updated array to spsublist.dat") async with aiof.open('spsublist.dat', 'wb') as datafile: pickled_spsublist = pickle.dumps(spsublist) - await datafile.write(spsublist) + await datafile.write(pickled_spsublist) #await datafile.fsync() await datafile.flush() -- 2.39.5 From 7bab9a123881ebd3ef2b05f7524cb1e9bf6fa564 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 23:38:56 -0400 Subject: [PATCH 17/88] setting protocol to 4 --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index c687911..68d6b82 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -674,7 +674,7 @@ async def spsub_T(ctx, service = "NONE"): #Write updated array to data file print(">> Writing updated array to spsublist.dat") async with aiof.open('spsublist.dat', 'wb') as datafile: - pickled_spsublist = pickle.dumps(spsublist) + pickled_spsublist = pickle.dumps(spsublist, protocol=4) await datafile.write(pickled_spsublist) #await datafile.fsync() await datafile.flush() -- 2.39.5 From 8480215db9c7ffc3877b11d4bfe6de214b67a4e7 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 23:43:16 -0400 Subject: [PATCH 18/88] changing assignment --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 68d6b82..7a35dc4 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -669,7 +669,7 @@ async def spsub_T(ctx, service = "NONE"): spsublist[currentsub_request[1]] = '' spsublist[currentsub_request[1]]['state'] = 'online' - spsublist[currentsub_request[1]]['channels'].append(currentsub_request[0]) + spsublist[currentsub_request[1]]['channels'] = [f'{currentsub_request[0]}'] #Write updated array to data file print(">> Writing updated array to spsublist.dat") -- 2.39.5 From 67309f592580236d21c0d379df07e41917e1a784 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 23:45:26 -0400 Subject: [PATCH 19/88] adding debug output --- r0b3bot.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/r0b3bot.py b/r0b3bot.py index 7a35dc4..1bb54b4 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -667,8 +667,11 @@ async def spsub_T(ctx, service = "NONE"): # append new subscription to dict print(">> Creating new dictionary") + print(">> Adding service") spsublist[currentsub_request[1]] = '' + print(">> Adding initial state") spsublist[currentsub_request[1]]['state'] = 'online' + print(">> Adding Channel") spsublist[currentsub_request[1]]['channels'] = [f'{currentsub_request[0]}'] #Write updated array to data file -- 2.39.5 From 84e6f8ed6d2245727c1d92e435a7654414e9c195 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 23:49:02 -0400 Subject: [PATCH 20/88] changing assignment --- r0b3bot.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 1bb54b4..a4a19fe 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -667,12 +667,13 @@ async def spsub_T(ctx, service = "NONE"): # append new subscription to dict print(">> Creating new dictionary") - print(">> Adding service") - spsublist[currentsub_request[1]] = '' - print(">> Adding initial state") - spsublist[currentsub_request[1]]['state'] = 'online' - print(">> Adding Channel") - spsublist[currentsub_request[1]]['channels'] = [f'{currentsub_request[0]}'] + #print(">> Adding service") + spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]} + #print(">> Adding initial state") + #spsublist[currentsub_request[1]]['state'] + #spsublist[currentsub_request[1]]['state'] = 'online' + #print(">> Adding Channel") + #spsublist[currentsub_request[1]]['channels'] = [f'{currentsub_request[0]}'] #Write updated array to data file print(">> Writing updated array to spsublist.dat") -- 2.39.5 From e0d77bf82dcf6659845d119d7e6e2687898fed82 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 23:49:50 -0400 Subject: [PATCH 21/88] forgot closing ] --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index a4a19fe..0cbe8cb 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -668,7 +668,7 @@ async def spsub_T(ctx, service = "NONE"): print(">> Creating new dictionary") #print(">> Adding service") - spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]} + spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]} #print(">> Adding initial state") #spsublist[currentsub_request[1]]['state'] #spsublist[currentsub_request[1]]['state'] = 'online' -- 2.39.5 From 4a27acb4ac7ea71df5acda7612285d2988896d1c Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 23:53:42 -0400 Subject: [PATCH 22/88] updated for loop --- r0b3bot.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 0cbe8cb..a6ced42 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -666,17 +666,10 @@ async def spsub_T(ctx, service = "NONE"): # append new subscription to dict print(">> Creating new dictionary") - - #print(">> Adding service") spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]} - #print(">> Adding initial state") - #spsublist[currentsub_request[1]]['state'] - #spsublist[currentsub_request[1]]['state'] = 'online' - #print(">> Adding Channel") - #spsublist[currentsub_request[1]]['channels'] = [f'{currentsub_request[0]}'] #Write updated array to data file - print(">> Writing updated array to spsublist.dat") + print(">> Saving dictionary to spsublist.dat") async with aiof.open('spsublist.dat', 'wb') as datafile: pickled_spsublist = pickle.dumps(spsublist, protocol=4) await datafile.write(pickled_spsublist) @@ -685,8 +678,6 @@ async def spsub_T(ctx, service = "NONE"): print(">> Done") await ctx.send(f"'{service_state['name']}' added to monitored services") - - #await sp_monitor(currentsub_request) else: print(f">> '{service}' does not exist, cancelling subscription") @@ -709,7 +700,7 @@ async def StatPing_Monitor(): pickled_spsublist = await datafile.read() spsublist = pickle.loads(pickled_spsublist) - for service, info in spsublist: + for service in spsublist.keys(): # service used to be subscription status = await get_stp_status(service) -- 2.39.5 From c7216563e6f89196507fa796354644da12072403 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Sun, 12 Apr 2020 23:56:36 -0400 Subject: [PATCH 23/88] changing assignment type --- r0b3bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index a6ced42..50608e5 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -666,7 +666,7 @@ async def spsub_T(ctx, service = "NONE"): # append new subscription to dict print(">> Creating new dictionary") - spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]} + spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : (currentsub_request[0])} #Write updated array to data file print(">> Saving dictionary to spsublist.dat") @@ -705,7 +705,7 @@ async def StatPing_Monitor(): status = await get_stp_status(service) - if status['online'] and service['state'] == "online": + if status['online'] and service['state'] == 'online': # nothing has changed, no alert needed await asyncio.sleep(1) -- 2.39.5 From 1fc96f6b3a3175155f44d3516f7e933f52b3e005 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 16:17:00 -0400 Subject: [PATCH 24/88] adding debug print --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 50608e5..84fdaac 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -704,7 +704,7 @@ async def StatPing_Monitor(): # service used to be subscription status = await get_stp_status(service) - + print(f"{service}") if status['online'] and service['state'] == 'online': # nothing has changed, no alert needed -- 2.39.5 From 3b6c82d6f58b37e8bd1396b1056cdec55c10380f Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 16:19:14 -0400 Subject: [PATCH 25/88] fixed iteration --- r0b3bot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 84fdaac..2205aab 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -704,12 +704,12 @@ async def StatPing_Monitor(): # service used to be subscription status = await get_stp_status(service) - print(f"{service}") - if status['online'] and service['state'] == 'online': + #print(f"{service}") + if status['online'] and spsublist[service]['state'] == 'online': # nothing has changed, no alert needed await asyncio.sleep(1) - elif not status['online'] and service['state'] == "offline": + elif not status['online'] and spsublist[service]['state'] == "offline": # again, nothing has changed no alert needed await asyncio.sleep(1) -- 2.39.5 From 71231d3a9b0ef26018861080207b39a4887a2aeb Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 16:24:56 -0400 Subject: [PATCH 26/88] testing variable --- r0b3bot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 2205aab..16b1662 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -704,7 +704,8 @@ async def StatPing_Monitor(): # service used to be subscription status = await get_stp_status(service) - #print(f"{service}") + print(f"{service}") + print(f"{spsublist[service]['state']}") if status['online'] and spsublist[service]['state'] == 'online': # nothing has changed, no alert needed -- 2.39.5 From 75121c5a792eafffcafed88309afb8155d14bb25 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 16:28:56 -0400 Subject: [PATCH 27/88] printing status varibale --- r0b3bot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/r0b3bot.py b/r0b3bot.py index 16b1662..7956244 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -706,6 +706,7 @@ async def StatPing_Monitor(): status = await get_stp_status(service) print(f"{service}") print(f"{spsublist[service]['state']}") + print(f"{status}") if status['online'] and spsublist[service]['state'] == 'online': # nothing has changed, no alert needed -- 2.39.5 From 1e58d5017dd27c32f7ba917a7785c1be180a4f96 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 16:59:14 -0400 Subject: [PATCH 28/88] adding debug --- r0b3bot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 7956244..d6eec5c 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -707,7 +707,7 @@ async def StatPing_Monitor(): print(f"{service}") print(f"{spsublist[service]['state']}") print(f"{status}") - if status['online'] and spsublist[service]['state'] == 'online': + if status and spsublist[service]['state'] == 'online': # nothing has changed, no alert needed await asyncio.sleep(1) @@ -805,6 +805,7 @@ async def get_stp_status(service): if spservice['name'].lower() == service: found = True + print(f"{spservice}") return spservice # Want to alert user if the service was not found -- 2.39.5 From eca6fae8979286cf28d10153ea29c8bbadb644b2 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 17:04:48 -0400 Subject: [PATCH 29/88] removed use of new_ --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index d6eec5c..90a64c4 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -739,7 +739,7 @@ async def StatPing_Monitor(): embed = discord.Embed(title=f"Service Alert", description=f"{service} is in an unknown state!", color=0xffff00) await ctx.send(embed=embed) - new_spsublist.append(subscription) + #new_spsublist.append(subscription) # Write status changes to spsublist.dat async with aiof.open('spsublist.dat', 'wb') as datafile: -- 2.39.5 From 5235df22596085f912494151e3fde5843905b8ae Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 17:08:58 -0400 Subject: [PATCH 30/88] init status --- r0b3bot.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 90a64c4..814e03e 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -702,7 +702,7 @@ async def StatPing_Monitor(): for service in spsublist.keys(): # service used to be subscription - + status = {} status = await get_stp_status(service) print(f"{service}") print(f"{spsublist[service]['state']}") @@ -805,7 +805,6 @@ async def get_stp_status(service): if spservice['name'].lower() == service: found = True - print(f"{spservice}") return spservice # Want to alert user if the service was not found -- 2.39.5 From 32144c5657ca0dec9be3e38663f4e7a86ccaef41 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 17:18:52 -0400 Subject: [PATCH 31/88] fixed comparison --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 814e03e..1c7af37 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -802,7 +802,7 @@ async def get_stp_status(service): for spservice in spservice_array.json(): # using lower() to eliminate any case mismatch problems - if spservice['name'].lower() == service: + if spservice['name'].lower() == service.lower(): found = True return spservice -- 2.39.5 From 9dfae705e552817786ce2b04fa0188d1f6c88923 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 17:23:42 -0400 Subject: [PATCH 32/88] now accounting for status not found response --- r0b3bot.py | 57 +++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 1c7af37..6366954 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -707,37 +707,38 @@ async def StatPing_Monitor(): print(f"{service}") print(f"{spsublist[service]['state']}") print(f"{status}") - if status and spsublist[service]['state'] == 'online': + if status != 'status not found': + if status['online'] and spsublist[service]['state'] == 'online': - # nothing has changed, no alert needed - await asyncio.sleep(1) - elif not status['online'] and spsublist[service]['state'] == "offline": - - # again, nothing has changed no alert needed - await asyncio.sleep(1) - else: - - print(f"Status of {service}' has changed, notifying subscribed channels") - - if status['online']: - for channel in service['channels']: - ctx = bot.get_channel(channel) - embed = discord.Embed(title=f"Service Alert", description=f"{service} is Online!", color=0x00ff40) - await ctx.send(embed=embed) - spsublist[service]['state'] = 'online' - - elif not status['online']: - for channel in service['channels']: - ctx = bot.get_channel(channel) - embed = discord.Embed(title=f"Service Alert", description=f"{service} is Offline!", color=0xff2200) - await ctx.send(embed=embed) - spsublist[service]['state'] = 'offline' + # nothing has changed, no alert needed + await asyncio.sleep(1) + elif not status['online'] and spsublist[service]['state'] == "offline": + # again, nothing has changed no alert needed + await asyncio.sleep(1) else: - for channel in service['channels']: - ctx = bot.get_channel(channel) - embed = discord.Embed(title=f"Service Alert", description=f"{service} is in an unknown state!", color=0xffff00) - await ctx.send(embed=embed) + + print(f"Status of {service}' has changed, notifying subscribed channels") + + if status['online']: + for channel in service['channels']: + ctx = bot.get_channel(channel) + embed = discord.Embed(title=f"Service Alert", description=f"{service} is Online!", color=0x00ff40) + await ctx.send(embed=embed) + spsublist[service]['state'] = 'online' + + elif not status['online']: + for channel in service['channels']: + ctx = bot.get_channel(channel) + embed = discord.Embed(title=f"Service Alert", description=f"{service} is Offline!", color=0xff2200) + await ctx.send(embed=embed) + spsublist[service]['state'] = 'offline' + + else: + for channel in service['channels']: + ctx = bot.get_channel(channel) + embed = discord.Embed(title=f"Service Alert", description=f"{service} is in an unknown state!", color=0xffff00) + await ctx.send(embed=embed) #new_spsublist.append(subscription) -- 2.39.5 From f94f69aa59efdbe45a53a8b6677df1f8114d23db Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 18:10:38 -0400 Subject: [PATCH 33/88] change debug --- r0b3bot.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 6366954..b5448cb 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -704,9 +704,8 @@ async def StatPing_Monitor(): # service used to be subscription status = {} status = await get_stp_status(service) - print(f"{service}") - print(f"{spsublist[service]['state']}") - print(f"{status}") + print(f"{service} Online: {status['online']}") + print(f" Previous state: {spsublist[service]['state']}") if status != 'status not found': if status['online'] and spsublist[service]['state'] == 'online': -- 2.39.5 From 153bc39e63f78b9c2bf5451b902fcf75b74ffb50 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 18:18:38 -0400 Subject: [PATCH 34/88] moved to single line --- r0b3bot.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index b5448cb..0dc6be4 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -702,10 +702,8 @@ async def StatPing_Monitor(): for service in spsublist.keys(): # service used to be subscription - status = {} status = await get_stp_status(service) - print(f"{service} Online: {status['online']}") - print(f" Previous state: {spsublist[service]['state']}") + print(f"{service} Online: {status['online']} | Previous state of 'online': {spsublist['online']}") if status != 'status not found': if status['online'] and spsublist[service]['state'] == 'online': -- 2.39.5 From e1327961b6f65730374dca93cb033ebc196fdd01 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 18:19:44 -0400 Subject: [PATCH 35/88] fixed --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 0dc6be4..45b7c19 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -703,7 +703,7 @@ async def StatPing_Monitor(): for service in spsublist.keys(): # service used to be subscription status = await get_stp_status(service) - print(f"{service} Online: {status['online']} | Previous state of 'online': {spsublist['online']}") + print(f"{service} Online: {status['online']} | Previous state of 'online': {spsublist[service]['online']}") if status != 'status not found': if status['online'] and spsublist[service]['state'] == 'online': -- 2.39.5 From 0544d870e70b191e427e86a7e6bfd4bb6a316ae2 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 18:22:27 -0400 Subject: [PATCH 36/88] fixed call --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 45b7c19..d73f94e 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -703,7 +703,7 @@ async def StatPing_Monitor(): for service in spsublist.keys(): # service used to be subscription status = await get_stp_status(service) - print(f"{service} Online: {status['online']} | Previous state of 'online': {spsublist[service]['online']}") + print(f"{service} Online: {status['online']} | Previous state of 'online': {spsublist[service]['state']}") if status != 'status not found': if status['online'] and spsublist[service]['state'] == 'online': -- 2.39.5 From 6a469832935a8b827551d46fb25331172c2e3b2d Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 18:23:09 -0400 Subject: [PATCH 37/88] changed wording for clarity --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index d73f94e..5e401bb 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -703,7 +703,7 @@ async def StatPing_Monitor(): for service in spsublist.keys(): # service used to be subscription status = await get_stp_status(service) - print(f"{service} Online: {status['online']} | Previous state of 'online': {spsublist[service]['state']}") + print(f"{service} Online: {status['online']} | Previous state: {spsublist[service]['state']}") if status != 'status not found': if status['online'] and spsublist[service]['state'] == 'online': -- 2.39.5 From 91def4cd4dc7b1210fddbd45e045cc4825baa57e Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 18:26:47 -0400 Subject: [PATCH 38/88] working on fixing iterations --- r0b3bot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 5e401bb..295913f 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -631,7 +631,7 @@ async def spsub_T(ctx, service = "NONE"): print(f">> '{service}' exists, adding to StatPing Monitor") await ctx.send(f"'{service_state['name']}' added to monitored services") currentsub_request.append(ctx.message.channel.id) - print(f">> channel ID: {ctx.message.channel}") + print(f">> channel ID: {ctx.message.channel.id}") #currentsub_request.append(ctx) currentsub_request.append(service_state['name']) currentsub_request.append("online") @@ -645,11 +645,11 @@ async def spsub_T(ctx, service = "NONE"): pickled_spsublist = await datafile.read() spsublist = pickle.loads(pickled_spsublist) - for service, info in spsublist.keys(): + for service in spsublist.keys(): # service = service_names # info = dict of service information - if service == currentsub_request[1]: + if service.lower() == currentsub_request[1].lower(): # This service matched what the user is trying to subscribe to # Now we need to check if this is for the same channel for channels in service['channels']: -- 2.39.5 From 64d80c79acaa1dc5725735b0c3c99fff161c922a Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 18:31:11 -0400 Subject: [PATCH 39/88] change to ctx.channel --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 295913f..24d8527 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -631,7 +631,7 @@ async def spsub_T(ctx, service = "NONE"): print(f">> '{service}' exists, adding to StatPing Monitor") await ctx.send(f"'{service_state['name']}' added to monitored services") currentsub_request.append(ctx.message.channel.id) - print(f">> channel ID: {ctx.message.channel.id}") + print(f">> channel ID: {ctx.channel.id}") #currentsub_request.append(ctx) currentsub_request.append(service_state['name']) currentsub_request.append("online") -- 2.39.5 From d9883b6f97fe9b4ca6c8720cf4338a687c724548 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 18:33:45 -0400 Subject: [PATCH 40/88] fixing iteration --- r0b3bot.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 24d8527..f6f4aa3 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -630,7 +630,7 @@ async def spsub_T(ctx, service = "NONE"): print(f">> '{service}' exists, adding to StatPing Monitor") await ctx.send(f"'{service_state['name']}' added to monitored services") - currentsub_request.append(ctx.message.channel.id) + currentsub_request.append(ctx.channel.id) print(f">> channel ID: {ctx.channel.id}") #currentsub_request.append(ctx) currentsub_request.append(service_state['name']) @@ -646,13 +646,12 @@ async def spsub_T(ctx, service = "NONE"): spsublist = pickle.loads(pickled_spsublist) for service in spsublist.keys(): - # service = service_names - # info = dict of service information + if service.lower() == currentsub_request[1].lower(): # This service matched what the user is trying to subscribe to # Now we need to check if this is for the same channel - for channels in service['channels']: + for channels in spsublist[service]['channels']: if channel == currentsub_request[0]: print(">> Subscribed Already") else: -- 2.39.5 From a265de4a628ad9314df46c78ba59c226411e7504 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 18:34:44 -0400 Subject: [PATCH 41/88] fixing typo --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index f6f4aa3..8d878c7 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -651,7 +651,7 @@ async def spsub_T(ctx, service = "NONE"): if service.lower() == currentsub_request[1].lower(): # This service matched what the user is trying to subscribe to # Now we need to check if this is for the same channel - for channels in spsublist[service]['channels']: + for channel in spsublist[service]['channels']: if channel == currentsub_request[0]: print(">> Subscribed Already") else: -- 2.39.5 From 861397b4559a3809dd39de912bc58f4ffe0ea1b2 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 18:41:11 -0400 Subject: [PATCH 42/88] fixing append --- r0b3bot.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 8d878c7..419f8ac 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -647,17 +647,19 @@ async def spsub_T(ctx, service = "NONE"): for service in spsublist.keys(): - if service.lower() == currentsub_request[1].lower(): # This service matched what the user is trying to subscribe to # Now we need to check if this is for the same channel + found_channel = False for channel in spsublist[service]['channels']: if channel == currentsub_request[0]: - print(">> Subscribed Already") - else: - # Append the current channel id to the list for this service - print(f">> Appending {currentsub_request[1]} to {channel}") - spsublist[service]['channels'].append(currentsub_request[1]) + print(f">> This channel is already subscribed to {service}") + found_channel = True + break + if not found_channel: + # Append the current channel id to the list for this service + print(f">> Appending {currentsub_request[1]} to {channel}") + spsublist[service]['channels'].append(currentsub_request[1]) else: @@ -676,7 +678,7 @@ async def spsub_T(ctx, service = "NONE"): await datafile.flush() print(">> Done") - await ctx.send(f"'{service_state['name']}' added to monitored services") + #await ctx.send(f"'{service_state['name']}' added to monitored services") else: print(f">> '{service}' does not exist, cancelling subscription") -- 2.39.5 From d58c7245e7272ee972b5f3b72dc068b4bb2ee822 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 18:50:25 -0400 Subject: [PATCH 43/88] clearing up console output --- r0b3bot.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 419f8ac..9edaa14 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -628,13 +628,15 @@ async def spsub_T(ctx, service = "NONE"): # If the service exists, proceed with adding it to the list. if service_state != "service not found": - print(f">> '{service}' exists, adding to StatPing Monitor") - await ctx.send(f"'{service_state['name']}' added to monitored services") + print(f">> '{service}' is a valid service on StatPing.") + print(f">> Checking if it has already been subscribed to" + #await ctx.send(f"'{service_state['name']}' added to monitored services") currentsub_request.append(ctx.channel.id) - print(f">> channel ID: {ctx.channel.id}") - #currentsub_request.append(ctx) currentsub_request.append(service_state['name']) currentsub_request.append("online") + print(f">> Channel ID: {currentsub_request[0]}") + print(f">> Service Name: {currentsub_request[1]}") + print(f">> Initial State to set: {currentsub_request[2]}") # read in data file containing dict of subscriptions print(">> Reading in spsublist.dat") @@ -647,6 +649,7 @@ async def spsub_T(ctx, service = "NONE"): for service in spsublist.keys(): + print(f">> Found {service} in data file, checking for channel") if service.lower() == currentsub_request[1].lower(): # This service matched what the user is trying to subscribe to # Now we need to check if this is for the same channel -- 2.39.5 From 1e62920925eab5a0c25a26f6e1aca893f38e565d Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 18:51:09 -0400 Subject: [PATCH 44/88] typo --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 9edaa14..cd47ed2 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -629,7 +629,7 @@ async def spsub_T(ctx, service = "NONE"): if service_state != "service not found": print(f">> '{service}' is a valid service on StatPing.") - print(f">> Checking if it has already been subscribed to" + print(f">> Checking if it has already been subscribed to") #await ctx.send(f"'{service_state['name']}' added to monitored services") currentsub_request.append(ctx.channel.id) currentsub_request.append(service_state['name']) -- 2.39.5 From 85cf5f5ce55592b5522311e720aa1019245c6df4 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 18:53:08 -0400 Subject: [PATCH 45/88] added confirmation message --- r0b3bot.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/r0b3bot.py b/r0b3bot.py index cd47ed2..30ecd28 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -671,6 +671,8 @@ async def spsub_T(ctx, service = "NONE"): # append new subscription to dict print(">> Creating new dictionary") spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : (currentsub_request[0])} + print(f">> {service} subscription has been saved") + await ctx.send(f"{service} has been added to monitored services for this channel") #Write updated array to data file print(">> Saving dictionary to spsublist.dat") -- 2.39.5 From fa2fb34e4127bb168605dc6b1df1bea847968ef4 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 18:56:24 -0400 Subject: [PATCH 46/88] moved print --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 30ecd28..c1a3341 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -649,10 +649,10 @@ async def spsub_T(ctx, service = "NONE"): for service in spsublist.keys(): - print(f">> Found {service} in data file, checking for channel") if service.lower() == currentsub_request[1].lower(): # This service matched what the user is trying to subscribe to # Now we need to check if this is for the same channel + print(f">> Found {service} in data file, checking for channel") found_channel = False for channel in spsublist[service]['channels']: if channel == currentsub_request[0]: -- 2.39.5 From f026c88817039d6b3454909191dc00f5bd82f0d8 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 19:00:27 -0400 Subject: [PATCH 47/88] change how saving channel --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index c1a3341..93583c1 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -670,7 +670,7 @@ async def spsub_T(ctx, service = "NONE"): # append new subscription to dict print(">> Creating new dictionary") - spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : (currentsub_request[0])} + spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : (f"{currentsub_request[0]}")} print(f">> {service} subscription has been saved") await ctx.send(f"{service} has been added to monitored services for this channel") -- 2.39.5 From 238bb9f5ea387686bb952414809c86df28a3be36 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 19:55:48 -0400 Subject: [PATCH 48/88] fixing dict creation --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 93583c1..75ea40b 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -670,7 +670,7 @@ async def spsub_T(ctx, service = "NONE"): # append new subscription to dict print(">> Creating new dictionary") - spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : (f"{currentsub_request[0]}")} + spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]} print(f">> {service} subscription has been saved") await ctx.send(f"{service} has been added to monitored services for this channel") -- 2.39.5 From f82227ea0db0d5b79be1fec8004dedd4971e2c11 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 19:57:56 -0400 Subject: [PATCH 49/88] adding notice to channel of duplicate --- r0b3bot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/r0b3bot.py b/r0b3bot.py index 75ea40b..89a74f5 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -657,6 +657,7 @@ async def spsub_T(ctx, service = "NONE"): for channel in spsublist[service]['channels']: if channel == currentsub_request[0]: print(f">> This channel is already subscribed to {service}") + await ctx.send(f"This channel is already subscribed to {service} alerts") found_channel = True break if not found_channel: -- 2.39.5 From 1a204d303b33915e861bf991cff9d37e1c70e749 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 20:02:47 -0400 Subject: [PATCH 50/88] fixing iteration --- r0b3bot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 89a74f5..b4f4c95 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -725,21 +725,21 @@ async def StatPing_Monitor(): print(f"Status of {service}' has changed, notifying subscribed channels") if status['online']: - for channel in service['channels']: + for channel in spsublist[service]['channels']: ctx = bot.get_channel(channel) embed = discord.Embed(title=f"Service Alert", description=f"{service} is Online!", color=0x00ff40) await ctx.send(embed=embed) spsublist[service]['state'] = 'online' elif not status['online']: - for channel in service['channels']: + for channel in spsublist[service]['channels']: ctx = bot.get_channel(channel) embed = discord.Embed(title=f"Service Alert", description=f"{service} is Offline!", color=0xff2200) await ctx.send(embed=embed) spsublist[service]['state'] = 'offline' else: - for channel in service['channels']: + for channel in spsublist[service]['channels']: ctx = bot.get_channel(channel) embed = discord.Embed(title=f"Service Alert", description=f"{service} is in an unknown state!", color=0xffff00) await ctx.send(embed=embed) -- 2.39.5 From 132267f5d4e1ba504c1f0c6b0863433e0b601347 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 20:05:03 -0400 Subject: [PATCH 51/88] adding more console output, fixed missing ' --- r0b3bot.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index b4f4c95..0883dc2 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -710,7 +710,7 @@ async def StatPing_Monitor(): for service in spsublist.keys(): # service used to be subscription status = await get_stp_status(service) - print(f"{service} Online: {status['online']} | Previous state: {spsublist[service]['state']}") + print(f">> {service} Online: {status['online']} | Previous state: {spsublist[service]['state']}") if status != 'status not found': if status['online'] and spsublist[service]['state'] == 'online': @@ -722,7 +722,7 @@ async def StatPing_Monitor(): await asyncio.sleep(1) else: - print(f"Status of {service}' has changed, notifying subscribed channels") + print(f">> Status of '{service}' has changed, notifying subscribed channels") if status['online']: for channel in spsublist[service]['channels']: @@ -743,6 +743,7 @@ async def StatPing_Monitor(): ctx = bot.get_channel(channel) embed = discord.Embed(title=f"Service Alert", description=f"{service} is in an unknown state!", color=0xffff00) await ctx.send(embed=embed) + print(">> Done") #new_spsublist.append(subscription) -- 2.39.5 From 98cf67381bbd78061256a333473ab269eeda74a1 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 20:07:28 -0400 Subject: [PATCH 52/88] adding response --- r0b3bot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 0883dc2..deb71db 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -662,7 +662,8 @@ async def spsub_T(ctx, service = "NONE"): break if not found_channel: # Append the current channel id to the list for this service - print(f">> Appending {currentsub_request[1]} to {channel}") + print(f">> Adding serivce '{currentsub_request[1]}' to {channel}") + await ctx.send(f"{service} has been added to monitored services for this channel") spsublist[service]['channels'].append(currentsub_request[1]) else: -- 2.39.5 From b26139fdac0c2958f4cef0550ab25e41fa859bb0 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 20:13:41 -0400 Subject: [PATCH 53/88] fixing append of channel id --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index deb71db..16ddaf7 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -664,7 +664,7 @@ async def spsub_T(ctx, service = "NONE"): # Append the current channel id to the list for this service print(f">> Adding serivce '{currentsub_request[1]}' to {channel}") await ctx.send(f"{service} has been added to monitored services for this channel") - spsublist[service]['channels'].append(currentsub_request[1]) + spsublist[service]['channels'].append(currentsub_request[0]) else: -- 2.39.5 From ce319f8696f3351cb3f94bb62b011b6b715cd342 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 20:38:29 -0400 Subject: [PATCH 54/88] added spsub- list --- r0b3bot.py | 52 ++++++++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 16ddaf7..ae8fba0 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -574,37 +574,10 @@ async def spalert(ctx, service = "NONE"): await ctx.send("Please speficy a service name to query.") - + @bot.command() async def spsub(ctx, service = "NONE"): - currentsub_request = [] - datestring = datetime.now() - datestring = datestring.strftime("%m/%d/%Y-%H:%M:%S") - print(f"[{datestring}]: {ctx.message.author.display_name} called '$spsub {service}'") - - if service != "NONE": - - print(f"Querying status of '{service}' to see if it exists") - service_state = await get_stp_status(service) - - if service_state != "service not found": - - print(f"'{service}' exists, starting monitor") - await ctx.send(f"'{service_state['name']}' added to monitored services") - currentsub_request.append(ctx) - currentsub_request.append(service) - currentsub_request.append("online") - - await sp_monitor(currentsub_request) - - else: - print(f"'{service}' does not exist, cancelling subscription") - await ctx.send(f"{service} was not found") - -@bot.command() -async def spsub_T(ctx, service = "NONE"): - spsublist = {} # Statping Subscription list to be read in from file # Structure of spsublist nested dictionary # spsublist[service name][list of channel ids][a state value] @@ -618,15 +591,34 @@ async def spsub_T(ctx, service = "NONE"): print(f"[{datestring}]: {ctx.message.author.display_name} called '$spsub {service}'") # Only work on this if the user has supplied a service name to monitor, a value of NONE - # means nothing was specified. + # means nothing was specified if service != "NONE": + if service == "-list": + # List the serivces that this channel is subscribed to + # Read in spsublist + sublist = '' + async with aiof.open('spsublist.dat', 'rb') as datafile: + pickled_spsublist = await datafile.read() + spsublist = pickle.loads(pickled_spsublist) + + for service in spsublist.keys(): + + for channel in spsublist[service]['channels']: + if channel == ctx.channel.id: + sublist += f"'{service}' " + + await ctx.send(f"This channel is subscribed to: {sublist}") + + elif service.startswith('-del '): + # Delete the service from this channels subscriptions + # Verify that the service name requested acutally exists print(f">> Querying status of '{service}' to see if it exists") service_state = await get_stp_status(service) # If the service exists, proceed with adding it to the list. - if service_state != "service not found": + elif if service_state != "service not found": print(f">> '{service}' is a valid service on StatPing.") print(f">> Checking if it has already been subscribed to") -- 2.39.5 From be04db6237cf62b46926fddeb729463687a5f3b2 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 20:39:06 -0400 Subject: [PATCH 55/88] fixing indents --- r0b3bot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index ae8fba0..038614c 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -613,9 +613,9 @@ async def spsub(ctx, service = "NONE"): elif service.startswith('-del '): # Delete the service from this channels subscriptions - # Verify that the service name requested acutally exists - print(f">> Querying status of '{service}' to see if it exists") - service_state = await get_stp_status(service) + # Verify that the service name requested acutally exists + print(f">> Querying status of '{service}' to see if it exists") + service_state = await get_stp_status(service) # If the service exists, proceed with adding it to the list. elif if service_state != "service not found": -- 2.39.5 From 10baa139a1e5582a96f37476f8e91a2d2f73685c Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 20:39:35 -0400 Subject: [PATCH 56/88] fix statement --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 038614c..d757b0f 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -618,7 +618,7 @@ async def spsub(ctx, service = "NONE"): service_state = await get_stp_status(service) # If the service exists, proceed with adding it to the list. - elif if service_state != "service not found": + elif service_state != "service not found": print(f">> '{service}' is a valid service on StatPing.") print(f">> Checking if it has already been subscribed to") -- 2.39.5 From d97a2d1fe304e264076a3e69ae2aad22da63402c Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 20:43:51 -0400 Subject: [PATCH 57/88] need to query before use --- r0b3bot.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index d757b0f..faac523 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -592,6 +592,11 @@ async def spsub(ctx, service = "NONE"): # Only work on this if the user has supplied a service name to monitor, a value of NONE # means nothing was specified + if service != "NONE" and service != "-list" and not service.startswith('-del '): + + print(f">> Querying status of '{service}' to see if it exists") + service_state = await get_stp_status(service) + if service != "NONE": if service == "-list": @@ -613,10 +618,6 @@ async def spsub(ctx, service = "NONE"): elif service.startswith('-del '): # Delete the service from this channels subscriptions - # Verify that the service name requested acutally exists - print(f">> Querying status of '{service}' to see if it exists") - service_state = await get_stp_status(service) - # If the service exists, proceed with adding it to the list. elif service_state != "service not found": -- 2.39.5 From 4c43ab0e8ea73b7294ca0946051641ab8b8099f4 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 20:44:33 -0400 Subject: [PATCH 58/88] added placeholder --- r0b3bot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index faac523..3da8d3e 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -617,7 +617,8 @@ async def spsub(ctx, service = "NONE"): elif service.startswith('-del '): # Delete the service from this channels subscriptions - + print("placeholder") + # If the service exists, proceed with adding it to the list. elif service_state != "service not found": -- 2.39.5 From a709f25ea3145f7a0db42f206c0f68ca49b8b92e Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 20:48:37 -0400 Subject: [PATCH 59/88] added consonle output --- r0b3bot.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 3da8d3e..2e80821 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -618,7 +618,7 @@ async def spsub(ctx, service = "NONE"): elif service.startswith('-del '): # Delete the service from this channels subscriptions print("placeholder") - + # If the service exists, proceed with adding it to the list. elif service_state != "service not found": @@ -633,9 +633,10 @@ async def spsub(ctx, service = "NONE"): print(f">> Initial State to set: {currentsub_request[2]}") # read in data file containing dict of subscriptions - print(">> Reading in spsublist.dat") + print(">> Checking for spsublist.dat") if os.path.exists('spsublist.dat'): + print(">> Data file exists, reading it in.") # Read in spsublist async with aiof.open('spsublist.dat', 'rb') as datafile: pickled_spsublist = await datafile.read() -- 2.39.5 From eeae88595d3b7110a7f3025637184b1bbb3d8a20 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 20:52:30 -0400 Subject: [PATCH 60/88] adding more console output --- r0b3bot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 2e80821..c1c8d78 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -642,8 +642,9 @@ async def spsub(ctx, service = "NONE"): pickled_spsublist = await datafile.read() spsublist = pickle.loads(pickled_spsublist) + print(f">> Checking if serivce is already in datafile") for service in spsublist.keys(): - + print(f">> Does {service.lower()} == {currentsub_request[1].lower()}") if service.lower() == currentsub_request[1].lower(): # This service matched what the user is trying to subscribe to # Now we need to check if this is for the same channel -- 2.39.5 From 824c952ad97f0ed5ef4895f812e118272a5b44f3 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 20:54:17 -0400 Subject: [PATCH 61/88] moved statement outside of loop --- r0b3bot.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index c1c8d78..6edf90e 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -656,11 +656,11 @@ async def spsub(ctx, service = "NONE"): await ctx.send(f"This channel is already subscribed to {service} alerts") found_channel = True break - if not found_channel: - # Append the current channel id to the list for this service - print(f">> Adding serivce '{currentsub_request[1]}' to {channel}") - await ctx.send(f"{service} has been added to monitored services for this channel") - spsublist[service]['channels'].append(currentsub_request[0]) + if not found_channel: + # Append the current channel id to the list for this service + print(f">> Adding serivce '{currentsub_request[1]}' to {channel}") + await ctx.send(f"{service} has been added to monitored services for this channel") + spsublist[service]['channels'].append(currentsub_request[0]) else: -- 2.39.5 From 576f21b6fca8a0d4791ff479d08fbea11419ecee Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 20:58:36 -0400 Subject: [PATCH 62/88] was not handling when serivce was not present in file --- r0b3bot.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 6edf90e..0479b03 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -645,7 +645,9 @@ async def spsub(ctx, service = "NONE"): print(f">> Checking if serivce is already in datafile") for service in spsublist.keys(): print(f">> Does {service.lower()} == {currentsub_request[1].lower()}") + found_service = False if service.lower() == currentsub_request[1].lower(): + found_service = True # This service matched what the user is trying to subscribe to # Now we need to check if this is for the same channel print(f">> Found {service} in data file, checking for channel") @@ -656,7 +658,13 @@ async def spsub(ctx, service = "NONE"): await ctx.send(f"This channel is already subscribed to {service} alerts") found_channel = True break - if not found_channel: + if not found_channel: + # Append the current channel id to the list for this service + print(f">> Adding serivce '{currentsub_request[1]}' to {channel}") + await ctx.send(f"{service} has been added to monitored services for this channel") + spsublist[service]['channels'].append(currentsub_request[0]) + + if not found_service: # Append the current channel id to the list for this service print(f">> Adding serivce '{currentsub_request[1]}' to {channel}") await ctx.send(f"{service} has been added to monitored services for this channel") -- 2.39.5 From 0bf0134a8645e35fcbd33be291fb8c89e9a02b8b Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 20:59:54 -0400 Subject: [PATCH 63/88] changin variable --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 0479b03..d1a7d9f 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -666,7 +666,7 @@ async def spsub(ctx, service = "NONE"): if not found_service: # Append the current channel id to the list for this service - print(f">> Adding serivce '{currentsub_request[1]}' to {channel}") + print(f">> Adding serivce '{currentsub_request[1]}' to {ctx.channel.id}") await ctx.send(f"{service} has been added to monitored services for this channel") spsublist[service]['channels'].append(currentsub_request[0]) -- 2.39.5 From 6df3f8a55f1c3fd6a0a9015069f8164f66e589eb Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:01:16 -0400 Subject: [PATCH 64/88] doing it wrong --- r0b3bot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index d1a7d9f..2d74a85 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -668,7 +668,8 @@ async def spsub(ctx, service = "NONE"): # Append the current channel id to the list for this service print(f">> Adding serivce '{currentsub_request[1]}' to {ctx.channel.id}") await ctx.send(f"{service} has been added to monitored services for this channel") - spsublist[service]['channels'].append(currentsub_request[0]) + spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]} + #spsublist[service]['channels'].append(currentsub_request[0]) else: -- 2.39.5 From cc903753767ed819009bd010e78354fc66cdf0ec Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:05:02 -0400 Subject: [PATCH 65/88] using .update to append --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 2d74a85..c089675 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -668,7 +668,7 @@ async def spsub(ctx, service = "NONE"): # Append the current channel id to the list for this service print(f">> Adding serivce '{currentsub_request[1]}' to {ctx.channel.id}") await ctx.send(f"{service} has been added to monitored services for this channel") - spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]} + spsublist.update([currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]}) #spsublist[service]['channels'].append(currentsub_request[0]) else: -- 2.39.5 From c9c67f32c97f48984726a3ac4f2c87807ed72da7 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:05:53 -0400 Subject: [PATCH 66/88] typo? --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index c089675..e7cc572 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -668,7 +668,7 @@ async def spsub(ctx, service = "NONE"): # Append the current channel id to the list for this service print(f">> Adding serivce '{currentsub_request[1]}' to {ctx.channel.id}") await ctx.send(f"{service} has been added to monitored services for this channel") - spsublist.update([currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]}) + spsublist.update(currentsub_request[1] = {'state' : 'online', 'channels' : [currentsub_request[0]]}) #spsublist[service]['channels'].append(currentsub_request[0]) else: -- 2.39.5 From 9036557154000b40d35ece2794765380c42adedd Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:08:32 -0400 Subject: [PATCH 67/88] trying a different method --- r0b3bot.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index e7cc572..cee1726 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -668,7 +668,9 @@ async def spsub(ctx, service = "NONE"): # Append the current channel id to the list for this service print(f">> Adding serivce '{currentsub_request[1]}' to {ctx.channel.id}") await ctx.send(f"{service} has been added to monitored services for this channel") - spsublist.update(currentsub_request[1] = {'state' : 'online', 'channels' : [currentsub_request[0]]}) + newsub = {} + newsub[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]} + spsublist.update(newsub) #spsublist[service]['channels'].append(currentsub_request[0]) else: -- 2.39.5 From 87f82af6975d0938a16312a8f3dad15da0538260 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:18:17 -0400 Subject: [PATCH 68/88] ugh --- r0b3bot.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index cee1726..877d3e0 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -668,10 +668,9 @@ async def spsub(ctx, service = "NONE"): # Append the current channel id to the list for this service print(f">> Adding serivce '{currentsub_request[1]}' to {ctx.channel.id}") await ctx.send(f"{service} has been added to monitored services for this channel") - newsub = {} - newsub[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]} - spsublist.update(newsub) - #spsublist[service]['channels'].append(currentsub_request[0]) + #newsub = {} + #newsub[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]} + spsublist.update(currentsub_request[1] = {'state' : 'online', 'channels' : [currentsub_request[0]]}) else: -- 2.39.5 From bf2ac43a882fc03384b245963dea5336831df07d Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:18:50 -0400 Subject: [PATCH 69/88] typo --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 877d3e0..0cf02b4 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -670,7 +670,7 @@ async def spsub(ctx, service = "NONE"): await ctx.send(f"{service} has been added to monitored services for this channel") #newsub = {} #newsub[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]} - spsublist.update(currentsub_request[1] = {'state' : 'online', 'channels' : [currentsub_request[0]]}) + spsublist.update(currentsub_request[1] = {'state' : 'online', 'channels' : [currentsub_request[0]}) else: -- 2.39.5 From f051fe0087d40ae79234cd443927e3cf01d83a60 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:20:01 -0400 Subject: [PATCH 70/88] undo --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 0cf02b4..877d3e0 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -670,7 +670,7 @@ async def spsub(ctx, service = "NONE"): await ctx.send(f"{service} has been added to monitored services for this channel") #newsub = {} #newsub[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]} - spsublist.update(currentsub_request[1] = {'state' : 'online', 'channels' : [currentsub_request[0]}) + spsublist.update(currentsub_request[1] = {'state' : 'online', 'channels' : [currentsub_request[0]]}) else: -- 2.39.5 From c16fb46b785e1105a834f720d546047512168d01 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:24:13 -0400 Subject: [PATCH 71/88] does this work? --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 877d3e0..738fac4 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -670,7 +670,7 @@ async def spsub(ctx, service = "NONE"): await ctx.send(f"{service} has been added to monitored services for this channel") #newsub = {} #newsub[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]} - spsublist.update(currentsub_request[1] = {'state' : 'online', 'channels' : [currentsub_request[0]]}) + spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]}) else: -- 2.39.5 From 0e393b089fe6dae3fcc9a634a6ae21ccda64badd Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:25:32 -0400 Subject: [PATCH 72/88] typo --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 738fac4..ad11e9b 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -670,7 +670,7 @@ async def spsub(ctx, service = "NONE"): await ctx.send(f"{service} has been added to monitored services for this channel") #newsub = {} #newsub[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]} - spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]}) + spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]} else: -- 2.39.5 From d85149e5f197b0f9d426c2f1f5f74215dc5f97e8 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:29:41 -0400 Subject: [PATCH 73/88] seriously if this was it... ugh --- r0b3bot.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index ad11e9b..59f0f10 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -664,13 +664,13 @@ async def spsub(ctx, service = "NONE"): await ctx.send(f"{service} has been added to monitored services for this channel") spsublist[service]['channels'].append(currentsub_request[0]) - if not found_service: - # Append the current channel id to the list for this service - print(f">> Adding serivce '{currentsub_request[1]}' to {ctx.channel.id}") - await ctx.send(f"{service} has been added to monitored services for this channel") - #newsub = {} - #newsub[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]} - spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]} + if not found_service: + # Append the current channel id to the list for this service + print(f">> Adding serivce '{currentsub_request[1]}' to {ctx.channel.id}") + await ctx.send(f"{service} has been added to monitored services for this channel") + #newsub = {} + #newsub[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]} + spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]} else: -- 2.39.5 From 7e9be22734e8aac472f9f4049d74d024e16ed31f Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:32:31 -0400 Subject: [PATCH 74/88] changed spalert to spstatus --- r0b3bot.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 59f0f10..05f2752 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -550,7 +550,7 @@ async def info(ctx): bot.remove_command('help') @bot.command() -async def spalert(ctx, service = "NONE"): +async def spstatus(ctx, service = "NONE"): #async def spalert(ctx, cmd = "NONE", arg = "NONE"): # if cmd != "NONE": @@ -619,6 +619,7 @@ async def spsub(ctx, service = "NONE"): # Delete the service from this channels subscriptions print("placeholder") + # If the service exists, proceed with adding it to the list. elif service_state != "service not found": @@ -844,7 +845,7 @@ async def help(ctx): embed.add_field(name="$info", value="Gives a little info about the bot", inline=False) embed.add_field(name="$help", value="Gives this message", inline=False) embed.add_field(name="$last_error", value="Will display the real error message the bot has last encountered for additional debugging info") - embed.add_field(name="$spalert servicename", value="Retrieves status of service from StatPing") + embed.add_field(name="$spstatus servicename", value="Retrieves status of service from StatPing") await ctx.send(embed=embed) embed = discord.Embed(title="A note about sound clips:", description="Sound clips are only played in voice channels. If a user is not specified when calling the command, the sound will played in the channel of that issuing user is currently joined to. When a username is specified, the bot will play the sound in the channel that user is currently in.") -- 2.39.5 From 4ec07fdf7744a179477348d86e1666489480c4b7 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:34:45 -0400 Subject: [PATCH 75/88] changed info command prefix to variable --- r0b3bot.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 05f2752..e8b4d31 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -829,23 +829,23 @@ async def get_stp_status(service): @bot.command() async def help(ctx): embed = discord.Embed(title="R0b3BOT", description="List of commands are:", color=0xeee657) - embed.add_field(name="$printstat", value="Uploads a snapshot of Rich's 3D printer and current stats", inline=False) - embed.add_field(name="$explain", value="Displays Dalek EXPLAIN gif", inline=False) - embed.add_field(name="$holyshit", value="Displays Marty McFly HOLY SHIT gif", inline=False) - embed.add_field(name="$greetings", value="Gives a nice greet message", inline=False) - embed.add_field(name="$cat", value="Gives a cute cat gif to lighten up the mood.", inline=False) - embed.add_field(name="$bitch @member", value="Plays clip of BigEric420 saying 'maybe you shouldn't be such a bitch.mp3'", inline=False) - embed.add_field(name="$boom @member", value="Plays 'Boom Bitch' sound clip", inline=False) - embed.add_field(name="$cowbell @member", value="Plays 'SNL More Cowbell' sound clip", inline=False) - embed.add_field(name="$oops @member", value="Plays 'Oops.mp3'", inline=False) - embed.add_field(name="$promoted @member", value="Plays Battlefield Friends 'PROMOTED!' sound clip", inline=False) - embed.add_field(name="$trololo @member", value="Plays a clip of Trololo song", inline=False) - embed.add_field(name="$leeroy @member", value="Plays Leeeerrroooyyy Jenkins clip", inline=False) - embed.add_field(name="$eia @member", value="Plays 'Everything is Awesome' song clip") - embed.add_field(name="$info", value="Gives a little info about the bot", inline=False) - embed.add_field(name="$help", value="Gives this message", inline=False) - embed.add_field(name="$last_error", value="Will display the real error message the bot has last encountered for additional debugging info") - embed.add_field(name="$spstatus servicename", value="Retrieves status of service from StatPing") + embed.add_field(name=f"{BOT_COMMAND_PREFIX}printstat", value="Uploads a snapshot of Rich's 3D printer and current stats", inline=False) + embed.add_field(name=f"{BOT_COMMAND_PREFIX}explain", value="Displays Dalek EXPLAIN gif", inline=False) + embed.add_field(name=f"{BOT_COMMAND_PREFIX}holyshit", value="Displays Marty McFly HOLY SHIT gif", inline=False) + embed.add_field(name=f"{BOT_COMMAND_PREFIX}greetings", value="Gives a nice greet message", inline=False) + embed.add_field(name=f"{BOT_COMMAND_PREFIX}cat", value="Gives a cute cat gif to lighten up the mood.", inline=False) + embed.add_field(name=f"{BOT_COMMAND_PREFIX}bitch @member", value="Plays clip of BigEric420 saying 'maybe you shouldn't be such a bitch.mp3'", inline=False) + embed.add_field(name=f"{BOT_COMMAND_PREFIX}boom @member", value="Plays 'Boom Bitch' sound clip", inline=False) + embed.add_field(name=f"{BOT_COMMAND_PREFIX}cowbell @member", value="Plays 'SNL More Cowbell' sound clip", inline=False) + embed.add_field(name=f"{BOT_COMMAND_PREFIX}oops @member", value="Plays 'Oops.mp3'", inline=False) + embed.add_field(name=f"{BOT_COMMAND_PREFIX}promoted @member", value="Plays Battlefield Friends 'PROMOTED!' sound clip", inline=False) + embed.add_field(name=f"{BOT_COMMAND_PREFIX}trololo @member", value="Plays a clip of Trololo song", inline=False) + embed.add_field(name=f"{BOT_COMMAND_PREFIX}leeroy @member", value="Plays Leeeerrroooyyy Jenkins clip", inline=False) + embed.add_field(name=f"{BOT_COMMAND_PREFIX}eia @member", value="Plays 'Everything is Awesome' song clip") + embed.add_field(name=f"{BOT_COMMAND_PREFIX}info", value="Gives a little info about the bot", inline=False) + embed.add_field(name=f"{BOT_COMMAND_PREFIX}help", value="Gives this message", inline=False) + embed.add_field(name=f"{BOT_COMMAND_PREFIX}last_error", value="Will display the real error message the bot has last encountered for additional debugging info") + embed.add_field(name=f"{BOT_COMMAND_PREFIX}spstatus servicename", value="Retrieves status of service from StatPing") await ctx.send(embed=embed) embed = discord.Embed(title="A note about sound clips:", description="Sound clips are only played in voice channels. If a user is not specified when calling the command, the sound will played in the channel of that issuing user is currently joined to. When a username is specified, the bot will play the sound in the channel that user is currently in.") -- 2.39.5 From 8f9af7d10c70e255870ee81471fc20303eb93bfc Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:48:57 -0400 Subject: [PATCH 76/88] addd -del option --- r0b3bot.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/r0b3bot.py b/r0b3bot.py index e8b4d31..75cca0b 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -618,7 +618,30 @@ async def spsub(ctx, service = "NONE"): elif service.startswith('-del '): # Delete the service from this channels subscriptions print("placeholder") + service_toremove = service[5:] + print(f"{service_toremove}") + async with aiof.open('spsublist.dat', 'rb') as datafile: + pickled_spsublist = await datafile.read() + spsublist = pickle.loads(pickled_spsublist) + + found_service = False + for service in spsublist.keys(): + + if service.lower() == service_toremove.lower(): + found_service = True + found_channel = False + service_toremove = serivce + for channel in spsublist[service]['channels']: + if channel == ctx.channel.id: + found_service = True + spsublist[service]['channels'].remove(channel) + + if found_service and found_channel: + + await ctx.send(f"This channel is unsubscribed from '{service}' alerts.") + else: + await ctx.send(f"This channel is not subscribed to alerts for '{service_toremove}") # If the service exists, proceed with adding it to the list. elif service_state != "service not found": -- 2.39.5 From 7c1b3c207da749a2961fd6e0cc9b619c57e75bd0 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:51:55 -0400 Subject: [PATCH 77/88] changing option --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 75cca0b..ad3e616 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -615,7 +615,7 @@ async def spsub(ctx, service = "NONE"): await ctx.send(f"This channel is subscribed to: {sublist}") - elif service.startswith('-del '): + elif service.startswith('-del:'): # Delete the service from this channels subscriptions print("placeholder") service_toremove = service[5:] -- 2.39.5 From cc1368258c25b89cfb6f1f5f806b69efd345718b Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:53:10 -0400 Subject: [PATCH 78/88] fixing typo --- r0b3bot.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index ad3e616..eaac177 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -617,7 +617,6 @@ async def spsub(ctx, service = "NONE"): elif service.startswith('-del:'): # Delete the service from this channels subscriptions - print("placeholder") service_toremove = service[5:] print(f"{service_toremove}") @@ -631,7 +630,7 @@ async def spsub(ctx, service = "NONE"): if service.lower() == service_toremove.lower(): found_service = True found_channel = False - service_toremove = serivce + service_toremove = service for channel in spsublist[service]['channels']: if channel == ctx.channel.id: found_service = True -- 2.39.5 From faad238f8cb7847bde13e93c371bf1b8e0c24750 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:54:43 -0400 Subject: [PATCH 79/88] fix wrong vairable assignment --- r0b3bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index eaac177..972172e 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -633,14 +633,14 @@ async def spsub(ctx, service = "NONE"): service_toremove = service for channel in spsublist[service]['channels']: if channel == ctx.channel.id: - found_service = True + found_channel = True spsublist[service]['channels'].remove(channel) if found_service and found_channel: await ctx.send(f"This channel is unsubscribed from '{service}' alerts.") else: - await ctx.send(f"This channel is not subscribed to alerts for '{service_toremove}") + await ctx.send(f"This channel is not subscribed to alerts for '{service_toremove}''") # If the service exists, proceed with adding it to the list. elif service_state != "service not found": -- 2.39.5 From ba792ff1f5dc759c051bd277c45b280464ca55cb Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:57:15 -0400 Subject: [PATCH 80/88] moving indent out --- r0b3bot.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 972172e..0495ee0 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -705,16 +705,16 @@ async def spsub(ctx, service = "NONE"): print(f">> {service} subscription has been saved") await ctx.send(f"{service} has been added to monitored services for this channel") - #Write updated array to data file - print(">> Saving dictionary to spsublist.dat") - async with aiof.open('spsublist.dat', 'wb') as datafile: - pickled_spsublist = pickle.dumps(spsublist, protocol=4) - await datafile.write(pickled_spsublist) - #await datafile.fsync() - await datafile.flush() + #Write updated array to data file + print(">> Saving dictionary to spsublist.dat") + async with aiof.open('spsublist.dat', 'wb') as datafile: + pickled_spsublist = pickle.dumps(spsublist, protocol=4) + await datafile.write(pickled_spsublist) + #await datafile.fsync() + await datafile.flush() - print(">> Done") - #await ctx.send(f"'{service_state['name']}' added to monitored services") + print(">> Done") + #await ctx.send(f"'{service_state['name']}' added to monitored services") else: print(f">> '{service}' does not exist, cancelling subscription") -- 2.39.5 From d49d368895a33c1260f9715abc24a64b60cbf955 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:58:55 -0400 Subject: [PATCH 81/88] saving updated file --- r0b3bot.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 0495ee0..6499ebe 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -637,7 +637,12 @@ async def spsub(ctx, service = "NONE"): spsublist[service]['channels'].remove(channel) if found_service and found_channel: - + print(">> Saving dictionary to spsublist.dat") + async with aiof.open('spsublist.dat', 'wb') as datafile: + pickled_spsublist = pickle.dumps(spsublist, protocol=4) + await datafile.write(pickled_spsublist) + #await datafile.fsync() + await datafile.flush() await ctx.send(f"This channel is unsubscribed from '{service}' alerts.") else: await ctx.send(f"This channel is not subscribed to alerts for '{service_toremove}''") @@ -705,13 +710,13 @@ async def spsub(ctx, service = "NONE"): print(f">> {service} subscription has been saved") await ctx.send(f"{service} has been added to monitored services for this channel") - #Write updated array to data file - print(">> Saving dictionary to spsublist.dat") - async with aiof.open('spsublist.dat', 'wb') as datafile: - pickled_spsublist = pickle.dumps(spsublist, protocol=4) - await datafile.write(pickled_spsublist) - #await datafile.fsync() - await datafile.flush() + #Write updated array to data file + print(">> Saving dictionary to spsublist.dat") + async with aiof.open('spsublist.dat', 'wb') as datafile: + pickled_spsublist = pickle.dumps(spsublist, protocol=4) + await datafile.write(pickled_spsublist) + #await datafile.fsync() + await datafile.flush() print(">> Done") #await ctx.send(f"'{service_state['name']}' added to monitored services") -- 2.39.5 From a03efbd2a94d0570ce96a1272372984755fd3027 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 21:59:24 -0400 Subject: [PATCH 82/88] fix indent --- r0b3bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 6499ebe..7318e59 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -718,8 +718,8 @@ async def spsub(ctx, service = "NONE"): #await datafile.fsync() await datafile.flush() - print(">> Done") - #await ctx.send(f"'{service_state['name']}' added to monitored services") + print(">> Done") + #await ctx.send(f"'{service_state['name']}' added to monitored services") else: print(f">> '{service}' does not exist, cancelling subscription") -- 2.39.5 From 47e5c364a9fdac4a585f724058b46fac83ed101e Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 22:00:46 -0400 Subject: [PATCH 83/88] calling wrong variable --- r0b3bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 7318e59..c6a5172 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -688,7 +688,7 @@ async def spsub(ctx, service = "NONE"): break if not found_channel: # Append the current channel id to the list for this service - print(f">> Adding serivce '{currentsub_request[1]}' to {channel}") + print(f">> Adding serivce '{currentsub_request[1]}' to {ctx.channel.id}") await ctx.send(f"{service} has been added to monitored services for this channel") spsublist[service]['channels'].append(currentsub_request[0]) -- 2.39.5 From 2515eb83a5107d88e085bcee1a030450323c6ba1 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 22:04:34 -0400 Subject: [PATCH 84/88] changed when assigning service name --- r0b3bot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index c6a5172..29d89ec 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -630,11 +630,12 @@ async def spsub(ctx, service = "NONE"): if service.lower() == service_toremove.lower(): found_service = True found_channel = False - service_toremove = service for channel in spsublist[service]['channels']: if channel == ctx.channel.id: found_channel = True + service_toremove = service spsublist[service]['channels'].remove(channel) + break if found_service and found_channel: print(">> Saving dictionary to spsublist.dat") -- 2.39.5 From f37fc95ddc647cdcf2d84dd9afb1a569c292c41a Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 22:07:37 -0400 Subject: [PATCH 85/88] added break --- r0b3bot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/r0b3bot.py b/r0b3bot.py index 29d89ec..4098c91 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -692,6 +692,7 @@ async def spsub(ctx, service = "NONE"): print(f">> Adding serivce '{currentsub_request[1]}' to {ctx.channel.id}") await ctx.send(f"{service} has been added to monitored services for this channel") spsublist[service]['channels'].append(currentsub_request[0]) + break if not found_service: # Append the current channel id to the list for this service -- 2.39.5 From 1be2590f43b0dd077a9fcd248aa2c8c710271c0f Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 22:09:54 -0400 Subject: [PATCH 86/88] adding another break --- r0b3bot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/r0b3bot.py b/r0b3bot.py index 4098c91..74d3c96 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -636,6 +636,7 @@ async def spsub(ctx, service = "NONE"): service_toremove = service spsublist[service]['channels'].remove(channel) break + break if found_service and found_channel: print(">> Saving dictionary to spsublist.dat") -- 2.39.5 From ea2a76bf81a93b184e48223cc2bbe92d91ec75b3 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 22:30:09 -0400 Subject: [PATCH 87/88] adding breaks --- r0b3bot.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/r0b3bot.py b/r0b3bot.py index 74d3c96..6689614 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -620,23 +620,42 @@ async def spsub(ctx, service = "NONE"): service_toremove = service[5:] print(f"{service_toremove}") + # Open the data file for read in async with aiof.open('spsublist.dat', 'rb') as datafile: pickled_spsublist = await datafile.read() spsublist = pickle.loads(pickled_spsublist) + # We haven't found either the channel or servic; mark as false found_service = False + found_channel = False + + # Iterate through the service names in the data for service in spsublist.keys(): + # If the service we want to unsub from is the same as the service in the data, we need to search for the channel if service.lower() == service_toremove.lower(): + + # We've found the service match, mark as true found_service = True - found_channel = False + + # Iterate through the channels that are subbed to this service for channel in spsublist[service]['channels']: + + # If a channel listed in the service matches the current users channel id, we've found our match if channel == ctx.channel.id: + + # Marking channel as found found_channel = True + # Get the proper name of the service service_toremove = service - spsublist[service]['channels'].remove(channel) + #Remove the current users channel from this service + spsublist[service]['channels'].remove(ctx.channel.id) + # Break since we're done. break - break + + # If we got to the point of finding the channel, we're done. + if found_channel: + break if found_service and found_channel: print(">> Saving dictionary to spsublist.dat") @@ -673,15 +692,17 @@ async def spsub(ctx, service = "NONE"): spsublist = pickle.loads(pickled_spsublist) print(f">> Checking if serivce is already in datafile") + found_service = False + found_channel = False for service in spsublist.keys(): print(f">> Does {service.lower()} == {currentsub_request[1].lower()}") - found_service = False + if service.lower() == currentsub_request[1].lower(): found_service = True # This service matched what the user is trying to subscribe to # Now we need to check if this is for the same channel print(f">> Found {service} in data file, checking for channel") - found_channel = False + for channel in spsublist[service]['channels']: if channel == currentsub_request[0]: print(f">> This channel is already subscribed to {service}") -- 2.39.5 From 2a5ced954bdef195b4ed7be4073d2b73903dd0a8 Mon Sep 17 00:00:00 2001 From: Rich Oberholtzer Date: Mon, 13 Apr 2020 22:39:19 -0400 Subject: [PATCH 88/88] added new commands to help --- r0b3bot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/r0b3bot.py b/r0b3bot.py index 6689614..077cb43 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -897,6 +897,7 @@ async def help(ctx): embed.add_field(name=f"{BOT_COMMAND_PREFIX}help", value="Gives this message", inline=False) embed.add_field(name=f"{BOT_COMMAND_PREFIX}last_error", value="Will display the real error message the bot has last encountered for additional debugging info") embed.add_field(name=f"{BOT_COMMAND_PREFIX}spstatus servicename", value="Retrieves status of service from StatPing") + embed.add_field(name=f"{BOT_COMMAND_PREFIX}spsub service", value="Allows user to subscribe to service status change alerts for the channel. Can replace with -list and -del:service to manage alerts.") await ctx.send(embed=embed) embed = discord.Embed(title="A note about sound clips:", description="Sound clips are only played in voice channels. If a user is not specified when calling the command, the sound will played in the channel of that issuing user is currently joined to. When a username is specified, the bot will play the sound in the channel that user is currently in.") -- 2.39.5