Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
[RELEASE] merge Develop/1.3 into master

See merge request hull-seals/code/irc/halpybot!61
  • Loading branch information
Rixxan committed Mar 28, 2021
2 parents a546b99 + 4e5c454 commit c3447c9
Show file tree
Hide file tree
Showing 51 changed files with 2,082 additions and 212 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Virtual environment
/venv/
/halpy/

# Config files
/config/config.ini
Expand All @@ -9,3 +10,6 @@

# Python cache
**/__pycache__

#ideas and venv
/.idea
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# HalpyBOT 1.2.3
# HalpyBOT 1.3
This is the repository for HalpyBOT, the Hull Seals IRC Chatbot Assistant.

# Description
Expand All @@ -14,6 +14,8 @@ This bot is in ACTIVE DEVELOPMENT, with many core features not yet implemented.
- Pydle Python Library
- Pure-SASL Python Library
- MySQL Python Library
- NumPy Python Library
- Requests Python Library

## Usage
To install, download the latest [release](https://gitlab.com/hull-seals-cyberseals/irc/halpybot/-/tags) from our repository. Upload and extract the files to the directory or subdirectory you wish to install from, and create your own config.py to fit your server, following the example config file provided.
Expand Down
14 changes: 12 additions & 2 deletions config/config_template.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,18 @@ database =
joinable = #debrief, #Code-Black, #Repair-Requests, #bot-test, #cybers

[Offline Mode]
Enabled = False
enabled = False
announce_channels = #bot-test
warning override = False

[EDSM]
Maximum landmark distance = 10000
timeCached = 00:05:00

[Logging]
level = 'DEBUG'
level = 'DEBUG'

[Discord Notifications]
url = # Your Discord Webhook URL
CaseNotify = # In the format of <@&123456789123456789>
TrainedRole = # In the format of <@&123456789123456789>
50 changes: 36 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
HalpyBOT v1.2
HalpyBOT v1.3
> For the Hull Seals, with a boot to the head
Rixxan
Expand All @@ -13,23 +13,21 @@

import pydle
import logging
import src.packages.command.commandhandler as commandhandler
import asyncio
import signal
import functools

from src.packages.command import CommandGroup
from src.packages.announcer import announcer
from src.packages.database import facts
import configparser
from src.packages.database import facts, DatabaseConnection, NoDatabaseConnection
from src.packages.configmanager import config

config = configparser.ConfigParser()
config.read('config/config.ini')

channels = [entry.strip() for entry in config.get('Channels', 'ChannelList').split(',')]

logging.basicConfig(format='%(levelname)s\t%(name)s\t%(message)s',
logging.basicConfig(format='%(levelname)s\t%(name)s\t%(message)s',
level=logging._nameToLevel.get(config.get('Logging', 'level', fallback='DEBUG'), logging.DEBUG))


class HalpyBOT(pydle.Client):
# Join the Server and Channels and OperLine
async def on_connect(self):
Expand All @@ -42,24 +40,45 @@ async def on_connect(self):
for channel in channels:
await self.join(channel)
logging.info(f"Joining {channel}")
await self.offline_monitor()

async def on_channel_message(self, target, nick, message):
async def on_message(self, target, nick, message):
await super().on_channel_message(target, nick, message)
await commandhandler.on_channel_message(self, target, nick, message)
if message == f"{self.nickname} prefix":
return await self.message(target, f"Prefix: {config['IRC']['commandPrefix']}")
await CommandGroup.invoke_from_message(self, target, nick, message)
nicks = [entry.strip() for entry in config.get('Announcer', 'nicks').split(',')]
if target in config['Announcer']['channel'] and nick in nicks:
await announcer.on_channel_message(self, target, nick, message)

async def on_private_message(self, target, nick, message):
await super().on_private_message(target, nick, message)
await commandhandler.on_private_message(self, target, nick, message)

async def reply(self, channel: str, sender: str, in_channel: bool, message: str):
if in_channel:
await self.message(channel, message)
else:
await self.message(sender, message)

# FIXME this works for now but take a look at this when time allows.
async def offline_monitor(self):
logging.debug("STARTING OFFLINECHECK")
try:
loop = asyncio.get_running_loop()
while True:
if config['Offline Mode']['enabled'] == 'True' and \
config['Offline Mode']['warning override'] == 'False':
for ch in om_channels:
await self.message(ch, "HalpyBOT in OFFLINE mode! Database connection unavailable. "
"Contact a CyberSeal.")
await asyncio.sleep(300)
if config['Offline Mode']['enabled'] == 'False':
# We only need to start the connection, DatabaseConnection will trip the CB if neccesary
try:
DatabaseConnection()
except NoDatabaseConnection:
continue
await asyncio.sleep(300)
except asyncio.exceptions.CancelledError:
pass


# Define the Client, mostly pulled from config.ini
client = HalpyBOT(
Expand Down Expand Up @@ -91,6 +110,9 @@ async def shutdown(signal, loop):
results = await asyncio.gather(*tasks, return_exceptions=True)
loop.stop()


om_channels = [entry.strip() for entry in config.get('Offline Mode', 'announce_channels').split(',')]

LOOP = None

if __name__ == "__main__":
Expand Down
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ asyncio~=3.4.3
pure-sasl~=0.6.2
setuptools~=54.0.0
mysql-connector~=2.2.9
mysql~=0.0.2
mysql~=0.0.2
numpy~=1.20.1
requests~=2.25.1
pytest~=6.2.2
4 changes: 2 additions & 2 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from src.commands import *
from src.packages import *
from .commands import *
from .packages import *
30 changes: 4 additions & 26 deletions src/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
"""
HalpyBOT v1.1
commands\__init__.py - Command initialization script
Copyright (c) 2021 The Hull Seals,
All rights reserved.
Licensed under the GNU General Public License
See license.md
"""

from typing import List
from src.packages.command.commandhandler import Commands

from src.packages.command import Commands
from .announcer import *
from .bot_management import *
from .delayedboard import *
from .fact import *
from .forcejoin import *

@Commands.command("ping")
async def cmd_ping(ctx, args: List[str]):
"""
https://tinyurl.com/yylju9hg
Ping the bot, to check if it is alive
Usage: !ping
Aliases: n/a
"""
await ctx.reply("Pong!")
from .edsm import *
from .userinfo import *
from .utils import *
2 changes: 1 addition & 1 deletion src/commands/announcer/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from ..announcer import *
from .manual_case import *
62 changes: 42 additions & 20 deletions src/commands/announcer/manual_case.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
HalpyBOT v1.2
HalpyBOT v1.3
manual_case.py - Manual case creation module
Expand All @@ -11,12 +11,12 @@
"""

from typing import List
from src.packages.checks.checks import require_permission, DeniedMessage
import logging
from src.packages.checks.checks import require_channel
from .. import Commands
import requests

send_to = ["#Repair-Requests", "#seal-bob"]
from ...packages.checks import *
from .. import Commands
from ...packages.configmanager import config

@Commands.command("manualcase", "mancase")
@require_channel()
Expand All @@ -31,13 +31,19 @@ async def cmd_manual_case(ctx, args: List[str]):
message = f"xxxx MANCASE -- NEWCASE xxxx\n" \
f"{' '.join(args)}\n" \
f"xxxxxxxx"
for ch in send_to:
for ch in config['Announcer.cases']['channels'].split(", "):
await ctx.bot.message(ch, message)
logging.info(f"Manual case by {ctx.sender} in {ctx.channel}: {args}")
cn_message = f"New Manual Case Available -- <@&744998165714829334>\n" \
f"{' '.join(args)}"
await ctx.bot.message("#case-notify", cn_message)

cn_message = {
"content" : f"New Manual Case -- " + config['Discord Notifications']['CaseNotify'] + "\n" \
f"{' '.join(args)}",
"username" : "HalpyBOT"
}
url = config['Discord Notifications']['URL']
try:
requests.post(url, json=cn_message)
except requests.exceptions.HTTPError as err:
logging.error(err)

@Commands.command("manualfish", "manfish")
@require_channel()
Expand All @@ -52,24 +58,40 @@ async def cmd_manual_kingfisher(ctx, args: List[str]):
message = f"xxxx MANKFCASE -- NEWCASE xxxx\n" \
f"{' '.join(args)}\n" \
f"xxxxxxxx"
for ch in send_to:
for ch in config['Announcer.cases']['channels'].split(", "):
await ctx.bot.message(ch, message)
logging.info(f"Manual kingfisher case by {ctx.sender} in {ctx.channel}: {args}")
cn_message = f"New Manual KFCase Available -- <@&744998165714829334>\n" \
f"{' '.join(args)}"
await ctx.bot.message("#case-notify", cn_message)
cn_message = {
"content" : f"New Manual Kingfisher Case -- " + config['Discord Notifications']['CaseNotify'] + "\n" \
f"{' '.join(args)}",
"username" : "HalpyBOT"
}
url = config['Discord Notifications']['URL']
try:
requests.post(url, json=cn_message)
except requests.exceptions.HTTPError as err:
logging.error(err)


@Commands.command("wssPing")
@Commands.command("tsping")
@require_channel()
@require_permission("DRILLED", message=DeniedMessage.DRILLED)
async def cmd_wss_ping(ctx, args: List[str]):
async def cmd_trained_ping(ctx, args: List[str]):
"""
Alert the "Why So Sealious" role that CMDRs are needed for this case. Annoying AF and not to be used lightly.
Alert the "Trained Seals" role in Discord that CMDRs are needed for this case. Annoying AF and not to be used lightly.
Usage: !wssPing
Usage: !tsping
Aliases: none
"""
cn_message = f"Message from {ctx.sender}: Attention to the Above Cases, Seals! -- <@&591822215238909966>"
await ctx.bot.message("#case-notify", cn_message)
logging.info(f"Manual kingfisher case by {ctx.sender} in {ctx.channel}: {args}")
cn_message = {
"content" : f"Attention to the Above Case, Seals! -- " + config['Discord Notifications']['TrainedRole'] + "\n" \
f"Message triggered by {ctx.sender}",
"username" : "HalpyBOT"
}
url = config['Discord Notifications']['URL']
try:
requests.post(url, json = cn_message)
except requests.exceptions.HTTPError as err:
logging.error(err)
await ctx.reply("Notification Sent!")
6 changes: 3 additions & 3 deletions src/commands/bot_management/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from ..bot_management.puppet import *
from ..bot_management.settings import *
from ..bot_management.shutdown import *
from .puppet import *
from .settings import *
from .shutdown import *
6 changes: 3 additions & 3 deletions src/commands/bot_management/puppet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
""""
HalpyBOT v1.2
HalpyBOT v1.3
puppet.py - Bot sock puppet
Expand All @@ -12,7 +12,7 @@

from typing import List

from src.packages.checks.checks import require_dm, require_permission, DeniedMessage
from ...packages.checks import *
from .. import Commands


Expand All @@ -26,4 +26,4 @@ async def cmd_say(ctx, args: List[str]):
Usage: !say [channel] [text]
Aliases: n/a
"""
await ctx.bot.message(str(args[0]), ' '.join(args[1:]))
await ctx.bot.message(str(args[0]), ' '.join(args[1:]))
Loading

0 comments on commit c3447c9

Please sign in to comment.