Added Digital2Discord module
Updated bot to allow live reloading Updated WillieTimer with a lock to ensure two sessions are not opened, causing an error Added output for config keys Updated README.md
This commit is contained in:
56
modules/Digital2Discord/cog.py
Normal file
56
modules/Digital2Discord/cog.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import re
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from discord.ext.tasks import loop
|
||||
|
||||
regex_string = re.compile('(?:\d{4}/\d{2}/\d{2})[ ]*(?:\d{2}:\d{2}:\d{2})[ ]*(?:Group call;)[ ]*(?:TG=\d*)[ ]*(?:\[[A-Za-z]+\])?[ ]*(?:RID=(\d+))[ ]*(?:\[([-0-9A-Za-z]+)\])?[ ]*(?:[0-9]+s)?')
|
||||
|
||||
class Discord2Digital(commands.Cog):
|
||||
def __init__(self, bot): #, mention_group='Superadmins', channel_id=757379843792044102):
|
||||
self.bot = bot
|
||||
self.message = None
|
||||
self.last_radio_id = "-"
|
||||
self.lock = False
|
||||
|
||||
@loop(seconds=.25)
|
||||
async def file_watcher(self):
|
||||
with open('C:/Users/Logan/Downloads/Installers/Cubic-Build/DSDPlus/DSDPlus.event', 'r') as event_file:
|
||||
event = event_file.readlines()[-1]
|
||||
cur_radio_id = regex_string.findall(str(event))
|
||||
if cur_radio_id and cur_radio_id != self.last_radio_id:
|
||||
self.last_radio_id = cur_radio_id
|
||||
radio_id = cur_radio_id[0][0]
|
||||
if cur_radio_id[0][1]:
|
||||
message_name = cur_radio_id[0][1]
|
||||
embed_msg = discord.Embed(title="Last Known Radio ID", description=f"{radio_id}", color=0x00ff00)
|
||||
if 'message_name' in locals():
|
||||
embed_msg.add_field(name="Unit Name", value=f"{message_name}", inline=True)
|
||||
await self.message.edit(embed=embed_msg)
|
||||
|
||||
@commands.command(help="This command will start the display of Radio IDs and Unit names (if known) for digital comms",
|
||||
brief="Starts the display for digital comms")
|
||||
async def display_rid(self, ctx, *, member: discord.Member = None):
|
||||
member = member or ctx.author.display_name
|
||||
if not self.lock:
|
||||
await ctx.send(f"Ok {member}, I will display the Radio IDs of digital communications")
|
||||
embed_msg = discord.Embed(title="Last Known Radio ID", description=f"-", color=0x00ff00)
|
||||
self.message = await ctx.send(embed=embed_msg)
|
||||
self.lock = True
|
||||
self.file_watcher.start()
|
||||
else:
|
||||
await ctx.send(f"{member}, there's already a display running. If you want me to stop it, @ me and say 'stop_display'")
|
||||
|
||||
@commands.command(help="", brief="Stops the digital comm display")
|
||||
async def stop_display(self, ctx, member: discord.Member = None):
|
||||
member = member or ctx.author.display_name
|
||||
if self.lock:
|
||||
self.file_watcher.stop()
|
||||
self.message.delete()
|
||||
print('Stopping monitor')
|
||||
self.lock = False
|
||||
else:
|
||||
await ctx.send(f"{member}, there's no display running. If you want me to start one, @ me and say 'display_rid'")
|
||||
|
||||
|
||||
def setup(bot: commands.Bot):
|
||||
bot.add_cog(Discord2Digital(bot))
|
||||
@@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
import datetime
|
||||
import discord
|
||||
from random import choice
|
||||
from discord.ext import commands
|
||||
from discord.ext.tasks import loop
|
||||
from BotResources import write_config_file
|
||||
@@ -11,6 +12,15 @@ class WillieTimer(commands.Cog):
|
||||
self.bot = bot
|
||||
self.mention_group = str(self.bot.Default_Mention_Group)
|
||||
self.channel_id = int(self.bot.Default_Channel_ID)
|
||||
self.lock = False
|
||||
self.message_pool = [
|
||||
"It's 4:20! It's time to light up!",
|
||||
"Willie wanted to let you know that IT'S 4:20!",
|
||||
"Can you smell what the rock is cooking? No? PROBABLY BECAUSE IT'S 4:20!",
|
||||
"Oh say can you see. By the blunts early light. IT'S 4:20!",
|
||||
"Hey, are you busy? I just wanted to let you know IT'S 4:20!",
|
||||
"You know, the funny thing about time is we often forget to pay attention to it and we miss out on things. ALMOST LIKE 4:20! LIGHT UP!"
|
||||
]
|
||||
|
||||
@loop(minutes=1)
|
||||
async def bg_timer(self):
|
||||
@@ -21,20 +31,28 @@ class WillieTimer(commands.Cog):
|
||||
if datetime.datetime.now().strftime('%H:%M') in ("04:20", "16:20"):
|
||||
print(f"It's {datetime.datetime.now().strftime('%H:%M:%S')}!")
|
||||
channel = self.bot.get_channel(id=self.channel_id)
|
||||
await channel.send(f"<@&{self.bot_get_role().id}> It's 4:20! It's time to light up!")
|
||||
await channel.send(f"<@&{self.bot_get_role().id}> {choice(self.message_pool)}")
|
||||
|
||||
@commands.command(help="Use this command to start the background task to wait for 4:20",
|
||||
brief="Starts the 4:20 clock")
|
||||
async def start420(self, ctx, *, member: discord.Member = None):
|
||||
member = member or ctx.author.display_name
|
||||
await ctx.send(f"Thanks {member}, Willie will be in touch soon...")
|
||||
self.bg_timer.start()
|
||||
if not self.lock:
|
||||
await ctx.send(f"Thanks {member}, Willie will be in touch soon...")
|
||||
self.lock = True
|
||||
self.bg_timer.start()
|
||||
else:
|
||||
await ctx.send(f"I already told Willie {member}, if you want me to tell him to stop, @ me and say 'stop420'")
|
||||
|
||||
@commands.command(help="", brief="Stops the 4:20 clock")
|
||||
async def stop420(self, ctx, *, member: discord.Member = None):
|
||||
member = member or ctx.author.display_name
|
||||
await ctx.send(f"Ok {member}, Willie will go back to writing music...")
|
||||
self.bg_timer.stop()
|
||||
if self.lock:
|
||||
await ctx.send(f"Ok {member}, Willie will go back to writing music...")
|
||||
self.bg_timer.stop()
|
||||
self.lock = False
|
||||
else:
|
||||
await ctx.send(f"{member} I haven't told Willie yet. If you want me to, @ me and say 'start420'")
|
||||
|
||||
@commands.command(help="Example '@Greada chchn 757379843792044102'",
|
||||
brief="Change the channel the bot chats in at 4:20")
|
||||
Reference in New Issue
Block a user