Author SHA1 Message Date
Bradley 81f91df8ac Adding a fix for when new calls are starting in voice channels that haven't been registered yet 2024-01-08 06:47:22 -05:00
Bradley 6c6c2655f2 Adding another protection to try to avoid multiple recordings of the same audio happening 2024-01-07 16:23:42 -05:00
Bradley 6012351b3e Attempting to protect against call echo AND fix new call registry which wasn't working correctly it seems... 2024-01-07 15:30:15 -05:00
Bradley 934fa4d37f Setting auto commit on the db connection to true because apparently it defaults to false. Meaning nothing gets written to the DB 2024-01-06 15:48:08 -05:00
Bradley 44982fd439 Pushing up an attempted fix for breadmixer not being able to submit transcriptions to the database 2024-01-06 15:35:12 -05:00
Bradley 46fdebd503 Another minor fix for breadmixer, specifically the final ffmpeg call 2024-01-05 19:34:16 -05:00
Bradley c294489a60 Attempted fixes for breadmixers ffmpeg issues 2024-01-05 19:32:17 -05:00
Bradley 2cf2ec7d88 Trying to figure out what is wrong with breadmixer running the FFMPEG command that I know for certain works 2024-01-05 19:06:24 -05:00
Bradley 2f03a0de4c Fix for breadbot filter strings 2024-01-05 18:54:45 -05:00
Bradley 3b33bb6ee4 Cleanup, database structure backup, and an additional log item for breadmixer to try to figure out where the ffmpeg command structure is wrong 2024-01-05 18:51:11 -05:00
Bradley f7e0c4b15a Some cleanup, and transitioning breadbot.js to use winston for logging 2024-01-04 20:27:31 -05:00
Bradley 9fc901a2ef Pushing changes to sqlutil to add winston logging 2024-01-04 19:49:44 -05:00
Bradley b7283c17b6 A minor change to how servers are registered, bad logic 2024-01-03 21:06:50 -05:00
Bradley 40f6ea7cd7 A minor modification to how edited messages are handled to deal with how discord changes links to gifs and other media to what I assume are embeds 2024-01-02 21:50:47 -05:00
Bradley cb94d94943 Drastically lowering the end time duration of a speaking session in voice calls to see if event emitter warnings go away 2024-01-02 21:32:45 -05:00
Bradley 00b834c40b Adding another element to this to detect when someone stops speaking 2024-01-02 21:19:46 -05:00
Bradley a294b8c668 Minor fixes and adding a forgotten component of ending a call 2024-01-02 20:55:16 -05:00
Bradley 263405141b A number of changes to address issues and missing pieces from the voice call monitoring components of Breadbot 2024-01-02 20:39:23 -05:00
Bradley 089bb99119 Commands for breadbot seem to be missing, modifying deploy-command to fix this 2023-12-31 09:42:39 -05:00
Bradley 2f51c18a69 Trying some upgrades to command loading 2023-12-31 09:39:25 -05:00
Bradley 7afbb169e2 Another sql syntax fix 2023-12-30 18:53:32 -05:00
Bradley bdb9d4b807 Fixing a connection pool config to allow multiple statements per query 2023-12-30 18:37:28 -05:00
Bradley ed67193761 Fixing minor SQL syntax error 2023-12-30 18:34:36 -05:00
Bradley 18c9be444d Fixing a minor issue when adding messages 2023-12-30 18:30:10 -05:00
Bradley 40956e5c9e Adding message modify, delete, and attachment tracking (untested) 2023-12-30 17:32:44 -05:00
Bradley 4de56c1af8 Sort returns none, which was deleting the file dictionary items 2023-12-25 20:09:44 -05:00
Bradley 7b9a7fb339 Verbosity for breadmixer to try to figure out whats wrong 2023-12-25 19:23:20 -05:00
Bradley 3039bf65bd Adding breadmixer changes 2023-12-16 12:51:35 -05:00
Bradley 850e7288d1 A little more work on breadmixer 2023-11-29 20:59:50 -05:00
Bradley 3bbba3217a More fixes for dragging milliseconds out of the time diff 2023-11-24 20:50:22 -05:00
Bradley 7b0fde230d Really need milliseconds for seconds from starttime to be accurate 2023-11-24 20:46:42 -05:00
Bradley 511f4bf69e Fixing datatype coersion problems 2023-11-24 20:43:24 -05:00
Bradley 78f1232f5b Adding BreadMixer file indexing 2023-11-24 20:41:29 -05:00
Bradley 41683fe098 Ok, trying s instead of d, even though that's technically not correct 2023-11-24 20:16:03 -05:00
Bradley 61b617db04 I think we're back to typal pickiness 2023-11-24 20:13:42 -05:00
Bradley 740213712a Ok, the parameterization for queries is SUPER picky 2023-11-24 20:12:23 -05:00
Bradley 8cdd7d3974 It's not type coersion it's not seeing something as a tuple 2023-11-24 20:11:05 -05:00
Bradley e7681bf7cd Variable type coersion seems to be a problem with parameterized queries 2023-11-24 20:09:55 -05:00
Bradley 7bee11e4f4 Initial work on BreadMixer 2023-11-24 19:56:03 -05:00
Bradley 2954d1b304 Found something, might have been a node-crc dependency issue 2023-11-24 15:54:38 -05:00
Bradley 4868f6930e Trying a PCM write 2023-11-24 15:17:40 -05:00
Bradley 42f04a552a Attempting to write raw OPUS to file 2023-11-24 15:02:03 -05:00
Bradley 00de13acd2 Switched back to the old version and turning CRC back on 2023-11-22 21:57:26 -05:00
Bradley 9a5942facc Trying something because the files I'm getting are playable, but only under specify conditions and not with FFMEG 2023-11-22 21:40:34 -05:00
Bradley bdc0ed0fad Setting CRC false on the Ogg bitstream object to see if the problem with the CRC component goes away 2023-11-21 19:49:13 -05:00
Bradley 55490c4b04 Adding node-crc dependency 2023-11-21 19:33:30 -05:00
Bradley 66cec55bb6 Found a way to be more like the example code. Still not sure where the 2.0 alpha of prism comes from, but what the example uses I now have 2023-11-21 19:25:51 -05:00
Bradley 16b41fad2b Modifying versions and restoring the PCM version of audio saving 2023-11-21 18:46:06 -05:00
Bradley ab3ef81df9 Trying to write just straight ogg rather than convert to PCM, which seems to be the issue 2023-11-21 18:06:32 -05:00
Bradley 0f68356254 Possibly working version of joining voice call and collecting audio 2023-11-21 17:38:01 -05:00
Bradley 855a91e340 Trying something I found on Stack Overflow 2023-11-19 19:49:28 -05:00
Bradley 8ef2ede2c0 Trying another logging check to figure out this cache 2023-11-19 19:46:21 -05:00
Bradley 32954a2536 Fixed the problem with registering a new call id 2023-11-19 19:42:21 -05:00
Bradley a689783b36 Another commit 2023-11-19 19:39:07 -05:00
Bradley 9b0f381673 I DID PRINT AGAIN, JAVASCRIPT IS NOT PYTHON 2023-11-19 19:31:29 -05:00
Bradley 1eb4da8729 More debugging 2023-11-19 19:29:57 -05:00
Bradley 85fc4805dc Trying to fix the call registration return 2023-11-19 19:25:00 -05:00
Bradley f7bcbe348b Python is not Javascript, print doesn't exist 2023-11-19 19:22:00 -05:00
Bradley 2307119ad7 More random prints 2023-11-19 19:20:32 -05:00
Bradley d3daa299c0 Trying another sqlutil fix for inserting call state 2023-11-19 19:14:32 -05:00
Bradley abf8f10668 Modifications to fix some bugs with inputting ID 2023-11-19 19:10:55 -05:00
Bradley acaedb434c Adding a bunch of random minor changes to sqlutil to fix a lambda parameter problem 2023-11-19 19:00:41 -05:00
Bradley e64811a179 More debug messages 2023-11-19 18:57:34 -05:00
Bradley 113f6cbbd5 Adding a random debug message to see if what I think is happening is actually happening 2023-11-19 18:52:51 -05:00
Bradley 7c4b5c52f1 Fixing a minor object reference issue 2023-11-19 18:46:52 -05:00
Bradley b5ded6acaf Adding a bunch of debug logging 2023-11-19 18:44:22 -05:00
Bradley 08a9d0addd Another slight modification to make sure voice audio data is stored in a sensible location 2023-11-19 18:37:26 -05:00
Bradley aa1789da97 Adding a gitignore entry for media capture testing 2023-11-19 18:36:03 -05:00
Bradley 9e0c78d939 Major modifications to try out actual audio recording 2023-11-19 18:32:16 -05:00
Bradley d82c569363 Added a large amount of untested voice management code, stopping just short of actually connecting to/disconnecting from calls 2023-11-14 21:50:42 -05:00
Bradley 6effe2983e Some final updates for today, trying to keep track of how many people are in a particular voice channel 2023-11-12 14:54:42 -05:00
Bradley a729545e01 Fixing comparison states 2023-11-12 11:01:07 -05:00
Bradley 7e79b2c3b4 Adding an actual detection that says what user joined where 2023-11-12 10:58:09 -05:00
Bradley 87be8ca8db Doing to some state value checking now that the event works 2023-11-12 10:49:22 -05:00
Bradley 5507fea98e I think some misplaced brackets were causing the issues 2023-11-12 10:16:41 -05:00
Bradley 92df0cf4a7 Trying something simpler for VoiceStateChange notification just to see if the event works 2023-11-12 10:12:57 -05:00
Bradley 944f8d4e72 I'm pretty sure I used the wrong intent 2023-11-12 10:07:52 -05:00
Bradley 27e9fdb743 Missing an intent to capture the event that I want 2023-11-12 10:03:57 -05:00
Bradley b9a699c4c2 Adding preliminary test for Voice State Changed 2023-11-12 10:01:41 -05:00
Bradley 734aa58e67 Adding a 'Database Backup', it's not perfect, the queries are out of order, but it'll do for now if something blows up 2023-11-11 22:31:59 -05:00
Bradley dc323ffeb1 Some final cleanup, and README adjustments 2023-11-11 22:18:54 -05:00
Bradley 9fd8f3c289 Cleanup, and more logic fixes 2023-11-11 22:09:26 -05:00
Bradley c82fceeef1 Fixing some more logic problems 2023-11-11 22:02:31 -05:00
Bradley 01a72ca544 Fixing a logic error 2023-11-11 21:58:56 -05:00
Bradley 8befc32453 Trying a different way of handling the rows variable 2023-11-11 21:57:59 -05:00
Bradley 4a3e470945 Adding some more console noise for debugging 2023-11-11 21:56:07 -05:00
Bradley 7c6389d421 A significant amount of reimplementation 2023-11-11 21:51:34 -05:00
Bradley ac672e73d0 Pretty sure I have a working chain example 2023-11-11 21:29:05 -05:00
Bradley 43546d93fe More changes to promise chain testing 2023-11-11 21:23:49 -05:00
Bradley 6ea91cd1c9 Testing some stuff with promises and return values 2023-11-11 21:20:25 -05:00
Bradley 0ad30722ae Added more modifications, await doesn't seem to be respected in the way I'm thinking, so more logging! 2023-11-11 20:35:30 -05:00
Bradley dfeb3d5148 Trying to fix issues again, this time with the truthiness of promise objects 2023-11-11 20:21:24 -05:00
Bradley 6cbf6dc718 Trying to unwind some async/await mess 2023-11-11 20:17:59 -05:00
Bradley e24cc98fec Fixed some syncronization issues (I think) 2023-11-11 20:09:03 -05:00
Bradley a0e979e0bc The field for the message sender is author, not user 2023-11-11 19:52:27 -05:00
Bradley 69a711a4a4 Added some fancy intents to try to fix BreadBots deafness to new messages 2023-11-11 19:48:08 -05:00
Bradley 89e73e866b Adding greater console logging for event misfire 2023-11-11 19:43:23 -05:00
Bradley 77b526ca21 Added preliminary BreadBot message surveillance 2023-11-11 19:39:07 -05:00
Bradley 881b7f6359 I think I found a missing not directive 2023-11-11 18:37:24 -05:00
Bradley ece032ff5a Attempting to fix server already registered handling 2023-11-11 18:31:56 -05:00
Bradley dabb635b6b Trying another thing to fix escapement issues 2023-11-11 18:22:07 -05:00
Bradley 2de2202187 Fixing escapement issues 2023-11-11 18:18:09 -05:00
Bradley 3928b1f564 Fixed some insertion issue 2023-11-11 18:13:57 -05:00
Bradley 8865015499 Promises in JavaScript are neat and also a pain 2023-11-11 18:08:42 -05:00
Bradley 811478f486 More attempts to fix the situation with server registrations 2023-11-11 18:03:09 -05:00
Bradley 808ca6c442 Fix for isServerRegistered 2023-11-11 17:46:37 -05:00
Bradley cb3466c6c6 Adding server to database registration 2023-11-11 17:38:45 -05:00
Bradley 0d15e7931c Testing a new interaction 2023-11-11 15:33:57 -05:00
Bradley e68272236f Pushing up changes to main before I branch 2023-11-11 12:29:37 -05:00
Bradley febbd1fa8e Fixed Calendar Delete Issue 2022-11-29 21:37:23 -05:00
Bradley 0033bea4ab Fix README.md 2022-11-29 19:58:53 -05:00
Bradley d120cf9945 Update README.md 2022-11-29 19:57:57 -05:00
Bradley 24b97bc5b0 Adding some modifications to increase reuseability 2022-11-29 19:47:07 -05:00
Bradley 7ebdb84c98 Some mild changes, added list calendar 2022-11-25 19:41:08 -05:00
Bradley 30a2114ff4 Fixed addcalendar, added other file stubs 2022-11-24 17:39:30 -05:00
Bradley dce3b6ecc4 Committing a (non-functional) add calendar command 2022-11-22 19:54:42 -05:00
Bradley b2b8bccaa6 Committing psuedo functional GCal Pull
It's not exactly a good test, but it's something. Need to do some more
work in the creation and management of calendars.
2022-11-20 19:04:47 -05:00
Bradley 97af77745f gitignore modified to stop modules from being uploaded 2022-11-13 11:13:41 -05:00
Bradley 57fcb9f625 Commiting removal of node package folder 2022-11-13 11:11:13 -05:00
Bradley d5d6f84995 Push before general cleanup to avoid merge errors 2022-11-13 11:09:44 -05:00
Bradley a5196ef862 Continued Progress on Tutorial Following 2022-11-08 21:05:21 -05:00
Bradley 0333735ae5 Commit gitignore 2022-11-07 18:04:46 -05:00
Bradley 55ecf095a9 Insane number of adds to setup env and packages 2022-11-07 17:45:54 -05:00
Bradley 62c2bb73a9 Add rudimentary README.md 2022-11-06 20:37:50 -05:00
Bradley 7677072a25 Initial Commit 2022-11-06 20:27:48 -05:00
56 changed files with 3351 additions and 7059 deletions

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
{
"extends": "eslint:recommended",
"env": {
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 2021
},
"rules": {
"arrow-spacing": ["warn", { "before": true, "after": true }],
"brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
"comma-dangle": ["error", "always-multiline"],
"comma-spacing": "error",
"comma-style": "error",
"curly": ["error", "multi-line", "consistent"],
"dot-location": ["error", "property"],
"handle-callback-err": "off",
"indent": ["error", "tab"],
"keyword-spacing": "error",
"max-nested-callbacks": ["error", { "max": 4 }],
"max-statements-per-line": ["error", { "max": 2 }],
"no-console": "off",
"no-empty-function": "error",
"no-floating-decimal": "error",
"no-inline-comments": "error",
"no-lonely-if": "error",
"no-multi-spaces": "error",
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }],
"no-shadow": ["error", { "allow": ["err", "resolve", "reject"] }],
"no-trailing-spaces": ["error"],
"no-var": "error",
"object-curly-spacing": ["error", "always"],
"prefer-const": "error",
"quotes": ["error", "single"],
"semi": ["error", "always"],
"space-before-blocks": "error",
"space-before-function-paren": ["error", {
"anonymous": "never",
"named": "never",
"asyncArrow": "always"
}],
"space-in-parens": "error",
"space-infix-ops": "error",
"space-unary-ops": "error",
"spaced-comment": "error",
"yoda": "error"
}
}
+4 -2
View File
@@ -1,3 +1,5 @@
node_modules
.env .env
tools/ProfanityFilter/src/Words.json config.json
node_modules
keyfile.json
media
File diff suppressed because it is too large. Load diff
+22
View File
@@ -0,0 +1,22 @@
<h1>BreadBot</h1>
BreadBot helps, BreadBot does the things. Whatever things I'm willing to add to BreadBot.
BreadBot is the breadiest bread.
In all seriousness, BreadBot is my first real attempt at a Discord bot. I'm writing it such that it can really only be used in one server at the moment, although that will hopefully change in the future. The intention is really for it only to be used for the Team 2648 Discord server.
I have a subset of features that I want it to have before I call it "production ready" and a set of features that I want if I'm feeling adventurous and want to put in a lot of work.
"Production Ready" Features
- [ ] Google Calendar Integration for Event Management
- [ ] Create/Manage/Remove Events and Calendars
- [ ] Add Autocomplete for common elements like Calendar Names, Event Names, Timezones, etc.
- [ ] Calendar Announcements for Upcoming Events
- [ ] Poll Creation and Results Announcements
- [ ] Conversation Archiving (Partially working, need to work out edited messages, deleted messages, and attachments)
"Adventurous (Lots of Work)" Features
- [ ] BreadBot Voice Chat Hall Monitor
- [ ] Breadle (BreadBot Idle Bread Baking Game)
- [ ] BreadBot Calendar Send To Email
+201
View File
@@ -0,0 +1,201 @@
import argparse
import mysql.connector
import json
import os
import sys
import datetime
import subprocess
import random
import string
from txtai.pipeline import Transcription
from pprint import pprint
argument_parser = argparse.ArgumentParser(description="BreadMixer is used to combine media from Discord Voice Calls")
argument_parser.add_argument("callid", help="The call id that needs to be mixed")
argument_parser.add_argument("config", help="The BreadBot config file location")
argument_parser.add_argument("-f", "--filespercycle", help="The number of files to combine per run of ffmpeg", default=50)
argument_parser.add_argument("-v", "--verbose", help="Make the script tell you more about what it's doing", action="store_true")
args = argument_parser.parse_args()
if args.verbose:
print("Checking config file")
if not os.path.exists(args.config):
print('The file path {path} does not exist'.format(path=args.config))
sys.exit(1)
with open(args.config) as config:
json_config = json.loads(config.read())
config_must_contain = [
"mysql_username",
"mysql_password",
"mysql_db_name",
"mysql_host",
"media_voice_folder"
]
if not all([element in json_config for element in config_must_contain]):
print('One or more of the following config items are missing')
for element in config_must_contain:
print('\t{item}'.format(item=element))
sys.exit(2)
if args.verbose:
print("Connecting to mysql db {dbname}".format(dbname=json_config["mysql_db_name"]))
mydb = mysql.connector.connect(
host=json_config["mysql_host"],
user=json_config["mysql_username"],
password=json_config["mysql_password"],
database=json_config["mysql_db_name"]
)
mydb.autocommit = True
cursor = mydb.cursor()
if args.verbose:
print("Checking to see if call ID {callid} exists".format(callid=args.callid))
cursor.execute("SELECT call_start_time FROM call_states WHERE call_id = %s", [args.callid])
call_start_time = cursor.fetchall()
cursor.close()
if len(call_start_time) == 0:
print('{call_id} does not exist in the database'.format(call_id=args.callid))
sys.exit(3)
if args.verbose:
print("Collecting files from {folder}".format(folder=os.path.join(json_config["media_voice_folder"], args.callid)))
file_dict = {}
for file in os.listdir(os.path.join(json_config["media_voice_folder"], args.callid)):
file_name_no_ext = file.split('.')[0]
timestamp = int(file_name_no_ext.split('-')[0])
user_snowflake = file_name_no_ext.split('-')[1]
file_stamp_as_datetime = datetime.datetime.fromtimestamp(timestamp / 1000)
time_diff = file_stamp_as_datetime - call_start_time[0][0]
file_dict[os.path.join(json_config["media_voice_folder"], args.callid, file)] = dict(
user=user_snowflake,
real_date=file_stamp_as_datetime,
milliseconds_from_starttime=int((time_diff.seconds * 1000) + (time_diff.microseconds / 1000))
)
file_dict_items = [(k, v) for k, v in file_dict.items()]
file_dict_items.sort(key=lambda a: a[1]["milliseconds_from_starttime"])
if args.verbose:
print("Collected files: ")
[print(element) for element in file_dict_items]
list_of_final_merges = []
for i in range(0, len(file_dict_items), args.filespercycle):
input_list = []
filter_list = []
next_endpoint = i + 50 if i + 50 <= len(file_dict_items) else len(file_dict_items)
for j in range(i, next_endpoint, 1):
input_list.append(file_dict_items[j][0])
filter_list.append("[{inputid}]adelay={delay}|{delay}[a{inputid}]".format(
inputid = j - i,
delay = file_dict_items[j][1]["milliseconds_from_starttime"]
))
command_list = ["ffmpeg"]
for input in input_list:
command_list.append("-i")
command_list.append(input)
command_list.append("-filter_complex")
filter_string = "\""
filter_string = filter_string + ';'.join(filter_list)
filter_string = filter_string + ";"
for j in range(i, next_endpoint, 1):
filter_string = filter_string + "[a{inputid}]".format(inputid=j - i)
filter_string = filter_string + "amix=inputs={input_count}:normalize=0[a]\"".format(input_count = next_endpoint - i)
command_list.append(filter_string)
command_list.append("-map")
command_list.append("\"[a]\"")
output_file_name = os.path.join(
json_config["media_voice_folder"],
args.callid,
"intermediate-" + "".join(random.choices(string.ascii_uppercase + string.digits, k=10)) + ".mp3"
)
list_of_final_merges.append(output_file_name)
command_list.append(output_file_name)
ffmpeg_process = subprocess.Popen(' '.join(command_list), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
print(ffmpeg_process.args)
stdout, stderr = ffmpeg_process.communicate()
if (ffmpeg_process.returncode != 0):
print("The ffmpeg process failed")
print(stdout)
print(stderr)
sys.exit(5)
final_command_list = ["ffmpeg"]
for file in list_of_final_merges:
final_command_list.append("-i")
final_command_list.append(file)
final_command_list.append("-filter_complex")
filter_string = "\""
for i in range(len(list_of_final_merges)):
filter_string = filter_string + "[{inputid}]".format(inputid=i)
filter_string = filter_string + "amix=inputs={input_count}:normalize=0[a];[a]volume=3[boosted]\"".format(input_count=len(list_of_final_merges))
final_command_list.append(filter_string)
final_command_list.append("-map")
final_command_list.append("\"[boosted]\"")
final_command_list.append(os.path.join(json_config["media_voice_folder"], args.callid, "output.mp3"))
final_command_process = subprocess.Popen(' '.join(final_command_list), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout, stderr = final_command_process.communicate()
if (final_command_process.returncode != 0):
print("The final ffmpeg process failed")
print(stdout)
print(stderr)
sys.exit(6)
for file in os.listdir(os.path.join(json_config["media_voice_folder"], args.callid)):
if file.startswith("intermediate"):
os.remove(os.path.join(json_config["media_voice_folder"], args.callid, file))
transcribe = Transcription("openai/whisper-base")
for (k, v) in file_dict.items():
text = transcribe(k)
cursor = mydb.cursor()
cursor.execute("INSERT INTO call_transcriptions (call_id, user_snowflake, speaking_start_time, text) VALUES (%s, %s, %s, %s)", [
args.callid,
v["user"],
v["real_date"],
text
])
cursor.close()
+293
View File
@@ -0,0 +1,293 @@
const fs = require('node:fs');
const path = require('node:path');
const { Client, Events, GatewayIntentBits, Collection } = require('discord.js');
const { joinVoiceChannel, getVoiceConnection, entersState, VoiceConnectionStatus, EndBehaviorType } = require('@discordjs/voice')
const { token, media_voice_folder, breadbot_logging_config } = require('./config.json');
const winston = require('winston')
const winston_mysql = require('winston-mysql')
const sqlutil = require('./utilities/sqlutil');
const { Console } = require('node:console');
const prism = require('prism-media')
const logger = winston.createLogger({
level: "silly",
transports: [
new winston.transports.Console({
format: winston.format.simple(),
level: breadbot_logging_config["console_log_level"]
}),
new winston_mysql({
level: breadbot_logging_config["sql_log_level"],
host: breadbot_logging_config["mysql_host"],
user: breadbot_logging_config["mysql_username"],
password: breadbot_logging_config["mysql_password"],
database: breadbot_logging_config["mysql_db_name"],
table: breadbot_logging_config["mysql_table_name"]
})
]
})
sqlutil.buildPool()
const getAllFiles = function(directoryPath, arrayOfFiles) {
const files = fs.readdirSync(directoryPath);
arrayOfFiles = arrayOfFiles || [];
files.forEach(file => {
if (fs.statSync(directoryPath + path.sep + file).isDirectory()) {
arrayOfFiles = getAllFiles(directoryPath + path.sep + file, arrayOfFiles);
}
else {
arrayOfFiles.push(path.join(__dirname, directoryPath, path.sep, file));
}
});
return arrayOfFiles;
};
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildVoiceStates] });
client.commands = new Collection();
var activeCalls = []
getAllFiles('.' + path.sep + 'commands', [])
.filter(file => file.endsWith('.js'))
.forEach(file => {
const command = require(file);
if ('enabled' in command && command.enabled && 'data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
logger.info(`Loaded command at ${file}`)
}
else {
logger.warn(`The command at ${file} is missing a required "data" or "execute" property or is not enabled`)
}
});
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
logger.error(`No command matching ${interaction.commandName} was found`)
return;
}
try {
await command.execute(interaction);
}
catch (error) {
logger.error(error)
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
client.on(Events.GuildCreate, async guild => {
if (guild.available) {
logger.info(`Got into a server, ${guild.name}, ${guild.id}, ${guild.description}`)
sqlutil.registerServerIfMissing(guild.id, guild.name, guild.description).then(server_added => {
if(server_added) {
logger.info(`Server Added ${guild.name}`)
} else {
logger.error(`Server failed to add ${guild.name}`)
}
})
}
})
client.on(Events.VoiceStateUpdate, async (oldState, newState) => {
logger.info("Voice State Update Fired")
if (oldState.channel == null && newState.channel != null) {
if (newState.member.id == client.user.id) {
return //If the user is breadbot, ignore and exit
}
logger.info(`Channel Join Detected ${newState.guild.id} - ${newState.channelId} - ${newState.member.id}`)
//TODO Nothing should happen after this if the channel fails to register
await sqlutil.registerChannelIfMissing(newState.channel.id, newState.guild.id, newState.channel.name)
var existingCallID = await sqlutil.inCall(newState.guild.id, newState.channelId)
logger.info(`Existing call ID ${existingCallID}`)
if (existingCallID == -1) {
logger.info("Joining a call")
var newCallID = await sqlutil.registerNewCall(newState.guild.id, newState.channelId, new Date())
existingCallID = newCallID // To ensure all the stuff that happens after call creation works
logger.info(`Next call ID ${newCallID}`)
fs.mkdirSync(media_voice_folder + path.sep + newCallID, {recursive: true})
const connection = joinVoiceChannel({
channelId: newState.channelId,
guildId: newState.guild.id,
selfDeaf: false,
selfMute: true,
adapterCreator: newState.guild.voiceAdapterCreator
})
try {
await entersState(connection, VoiceConnectionStatus.Ready, 20e3)
const receiver = connection.receiver
if (receiver.speaking.listenerCount("start") == 0) {
receiver.speaking.on("start", (user_id) => {
if(!receiver.subscriptions.has(user_id)) {
receiver.subscribe(user_id, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 500
}
})
.pipe(new prism.opus.OggLogicalBitstream({
opusHead: new prism.opus.OpusHead({
channelCount: 2,
sampleRate: 48000
}),
pageSizeControl: {
maxPackets: 10
}
}))
.pipe(fs.createWriteStream(media_voice_folder + path.sep + newCallID + path.sep + `${Date.now()}-${user_id}.ogg`))
} else {
logger.warn(`Attempted to create new user subscriber for ${user_id} even though one already exists, receiver arm if statement protected against this`)
}
})
receiver.speaking.on("end", (user_id) => {
logger.info(`User ${user_id} stopped speaking`)
})
} else {
logger.warn("Attempted to create a new start and end listener for users who are speaking for some reason, receiver armor if statement protected against this")
}
} catch (error) {
logger.error(error)
}
}
var userRegistered = await sqlutil.registerUserIfMissing(newState.member.id, newState.member.username, newState.member.displayName)
if (userRegistered) {
var markedUserInCall = await sqlutil.registerUserInCall(existingCallID, newState.member.id)
if (!markedUserInCall) {
logger.error(`Something went wrong when marking user in voice call: ${newState.member.id} - ${newState.channelId}`)
}
} else {
logger.error(`Something went wrong when registering user for call: ${newState.member.id} - ${newState.member.username}`)
}
} else if (oldState.channel != null && newState.channel == null) {
if (oldState.member.id == client.user.id) {
return //If the user is breadbot, ignore and exit
}
logger.info(`Channel Exit Detected ${oldState.guild.id} - ${oldState.channelId} - ${oldState.member.id}`)
var existingCallID = await sqlutil.inCall(oldState.guild.id, oldState.channelId)
logger.info(`Existing call ID ${existingCallID}`)
if (existingCallID != -1) {
await sqlutil.deregisterUserInCall(existingCallID, oldState.member.id)
var usersInCall = await sqlutil.getNumberUsersInCall(existingCallID)
if (usersInCall == 0) {
const connection = getVoiceConnection(oldState.guild.id)
connection.disconnect()
var didUpdateEndTime = await sqlutil.updateCallEndTime(existingCallID, new Date())
if (!didUpdateEndTime) {
logger.error(`Failed to mark call ID ${existingCallID} as ended with an end date`)
}
}
} else {
logger.error("Couldn't find a call ID based on the guild and channel info, was Breadbot in the call?")
}
}
})
client.on(Events.MessageCreate, async message => {
console.info("Message Create Fired")
var channel_ok = await sqlutil.registerChannelIfMissing(message.channelId, message.channel.guild.id, message.channel.name)
var user_ok = await sqlutil.registerUserIfMissing(message.author.id, message.author.username, message.author.displayName)
logger.info(`Channel Ok? ${channel_ok} User OK? ${user_ok}`)
if (channel_ok && user_ok) {
await sqlutil.registerMessage(message.id, message.channelId, message.author.id, message.content, message.createdAt).then(async message_add => {
if(message_add) {
logger.info("Message Added")
if (message.attachments.size != 0) {
const all_attachments = message.attachments.map(attachment => sqlutil.registerAttachmentIfMissing(
attachment.id,
message.id,
attachment.name,
attachment.description,
message.createdAt,
attachment.contentType,
attachment.url
))
await Promise.all(all_attachments).catch((error) => {
logger.error(error)
})
}
} else {
logger.error("Failed to log message")
}
})
}
})
client.on(Events.MessageUpdate, async (oldMessage, newMessage) => {
logger.info("Message Update Fired")
logger.info(`Old Message Snowflake: ${oldMessage.id} New Message Snowflake: ${newMessage.id}`)
var editTime = newMessage.editedAt
if (editTime == null) {
editTime = newMessage.createdAt
}
await sqlutil.updateMessageContentIfPresent(newMessage.id, newMessage.content, editTime).then(async (updated) => {
if (updated) {
if (newMessage.attachments.size != 0) {
const all_attachments = newMessage.attachments.map(attachment => sqlutil.registerAttachmentIfMissing(
attachment.id,
newMessage.id,
attachment.name,
attachment.description,
editTime,
attachment.contentType,
attachment.url
))
await Promise.all(all_attachments).catch((error) => {
logger.error(error)
})
}
}
})
})
client.on(Events.MessageDelete, async deletedMessage => {
await sqlutil.markMessageDeletedIfPresent(deletedMessage.id)
})
client.once(Events.ClientReady, c => {
logger.info(`Ready! Logged in as ${c.user.tag} - ${c.user.id}`)
});
client.login(token);
+33
View File
@@ -0,0 +1,33 @@
const { google } = require('googleapis');
const { googlePrivateKey, googleClientEmail, googleProjectNumber } = require('./config.json');
const SCOPES = ['https://www.googleapis.com/auth/calendar'];
async function main() {
const jwtClient = new google.auth.JWT(
googleClientEmail,
null,
googlePrivateKey,
SCOPES,
);
const calendar = new google.calendar({
version: 'v3',
project: googleProjectNumber,
auth: jwtClient,
});
calendar.calendarList.list({}, (err, res) => {
if (err) {
console.log('[ERROR]');
console.log(err.errors);
return;
}
console.log(res.data.items.map(x => x.summary + '---' + x.timeZone));
});
}
main().catch(e => {
console.error(e);
throw e;
});
+37
View File
@@ -0,0 +1,37 @@
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { addCalendar } = require('../../utilities/googlecalendar.js');
// const { getTimeZones } = require('@vvo/tzdb');
module.exports = {
data: new SlashCommandBuilder()
.setName('addcalendar')
.setDescription('Creates a new Google Calendar')
.addStringOption(option =>
option
.setName('name')
.setDescription('The new name for the calendar')
.setRequired(true))
.addStringOption(option =>
option
.setName('timezone')
.setDescription('The Time Zone of this new calendar, must be in IANA format')
.setRequired(true)),
// .addChoices(getTimeZones().map(tz => {
// return { name: tz.name, value: tz.name };
// }))),
async execute(interaction) {
await interaction.deferReply({ ephemeral: true });
const name = interaction.options.getString('name');
const timezone = interaction.options.getString('timezone');
// eslint-disable-next-line no-unused-vars
addCalendar(name, timezone, async (success, message, extra) => {
const embedResponse = new EmbedBuilder()
.setColor(success ? 0x00FF00 : 0xFF0000)
.setTitle(message);
await interaction.editReply({ embeds: [ embedResponse ] });
});
},
};
View File
Whitespace-only changes.
+27
View File
@@ -0,0 +1,27 @@
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { deleteCalendar } = require('../../utilities/googlecalendar.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('deletecalendar')
.setDescription('Permanently deletes a calendar and it\'s associated events')
.addStringOption(option =>
option
.setName('name')
.setDescription('The name of the calendar you want to delete')
.setRequired(true)),
async execute(interaction) {
await interaction.deferReply({ ephemeral: true });
const name = interaction.options.getString('name');
// eslint-disable-next-line no-unused-vars
deleteCalendar(name, async (success, message, extra) => {
const embedResponse = new EmbedBuilder()
.setColor(success ? 0x0FF00 : 0xFF0000)
.setTitle(message);
await interaction.editReply({ embeds: [ embedResponse ] });
});
},
};
Whitespace-only changes.
+20
View File
@@ -0,0 +1,20 @@
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { getListOfCalendars } = require('../../utilities/googlecalendar');
module.exports = {
data: new SlashCommandBuilder()
.setName('listcalendars')
.setDescription('Lists the currently available calendars'),
async execute(interaction) {
await interaction.deferReply({ ephemeral: true });
getListOfCalendars({}, async (success, message, extra) => {
const embedResponse = new EmbedBuilder()
.setColor(success ? 0x00FF00 : 0xFF0000)
.setTitle(message)
.setDescription(extra.map(x => x.summary + ' --- ' + x.timeZone).join('\n\n'));
await interaction.editReply({ embeds: [ embedResponse ] });
});
},
};
Whitespace-only changes.
Whitespace-only changes.
+11
View File
@@ -0,0 +1,11 @@
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
enabled: true,
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
await interaction.reply('Pong!');
},
};
+12
View File
@@ -0,0 +1,12 @@
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
enabled: true,
data: new SlashCommandBuilder()
.setName('server')
.setDescription('Provides information about the server.'),
async execute(interaction) {
// interaction.guild is the object representing the Guild in which the command was run
await interaction.reply(`This server is ${interaction.guild.name} and has ${interaction.guild.memberCount} members.`);
},
};
+13
View File
@@ -0,0 +1,13 @@
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
enabled: true,
data: new SlashCommandBuilder()
.setName('user')
.setDescription('Provides information about the user.'),
async execute(interaction) {
// interaction.user is the object representing the User who ran the command
// interaction.member is the GuildMember object, which represents the user in the specific guild
await interaction.reply(`This command was run by ${interaction.user.username}, who joined on ${interaction.member.joinedAt}.`);
},
};
+178
View File
@@ -0,0 +1,178 @@
-- --------------------------------------------------------
-- Host: 192.168.1.196
-- Server version: 8.0.33 - MySQL Community Server - GPL
-- Server OS: Linux
-- HeidiSQL Version: 12.5.0.6677
-- --------------------------------------------------------
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
-- Dumping database structure for breadbot_test
CREATE DATABASE IF NOT EXISTS `breadbot_test` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
USE `breadbot_test`;
-- Dumping structure for table breadbot_test.call_states
CREATE TABLE IF NOT EXISTS `call_states` (
`call_id` int NOT NULL AUTO_INCREMENT,
`server_snowflake` bigint unsigned NOT NULL,
`channel_snowflake` bigint unsigned NOT NULL,
`call_start_time` datetime NOT NULL,
`call_end_time` datetime DEFAULT NULL,
`call_consolidated` bit(1) NOT NULL DEFAULT (0),
`call_transcribed` bit(1) NOT NULL DEFAULT (0),
`call_data_cleaned_up` bit(1) NOT NULL DEFAULT (0),
PRIMARY KEY (`call_id`),
KEY `fk_snowflake_recording_to_server` (`server_snowflake`),
KEY `fk_snowflake_recording_to_channel` (`channel_snowflake`),
CONSTRAINT `fk_snowflake_recording_to_channel` FOREIGN KEY (`channel_snowflake`) REFERENCES `channels` (`channel_snowflake`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `fk_snowflake_recording_to_server` FOREIGN KEY (`server_snowflake`) REFERENCES `servers` (`server_snowflake`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- Data exporting was unselected.
-- Dumping structure for table breadbot_test.call_transcriptions
CREATE TABLE IF NOT EXISTS `call_transcriptions` (
`transcription_id` int NOT NULL AUTO_INCREMENT,
`call_id` int NOT NULL,
`user_snowflake` bigint unsigned NOT NULL,
`speaking_start_time` datetime NOT NULL,
`text` longtext NOT NULL,
PRIMARY KEY (`transcription_id`),
KEY `fk_call_id_states_to_transcriptions` (`call_id`),
KEY `fk_snowflake_call_states_to_users` (`user_snowflake`),
CONSTRAINT `fk_call_id_states_to_transcriptions` FOREIGN KEY (`call_id`) REFERENCES `call_states` (`call_id`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `fk_snowflake_call_states_to_users` FOREIGN KEY (`user_snowflake`) REFERENCES `users` (`user_snowflake`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- Data exporting was unselected.
-- Dumping structure for table breadbot_test.call_users
CREATE TABLE IF NOT EXISTS `call_users` (
`call_users_id` int NOT NULL AUTO_INCREMENT,
`call_id` int NOT NULL,
`user_snowflake` bigint unsigned NOT NULL,
PRIMARY KEY (`call_users_id`) USING BTREE,
KEY `fk_call_id_call_user_to_state` (`call_id`),
KEY `fk_snowflake_call_user_to_users` (`user_snowflake`),
CONSTRAINT `fk_call_id_call_user_to_state` FOREIGN KEY (`call_id`) REFERENCES `call_states` (`call_id`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `fk_snowflake_call_user_to_users` FOREIGN KEY (`user_snowflake`) REFERENCES `users` (`user_snowflake`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- Data exporting was unselected.
-- Dumping structure for table breadbot_test.channels
CREATE TABLE IF NOT EXISTS `channels` (
`channel_snowflake` bigint unsigned NOT NULL,
`server_snowflake` bigint unsigned NOT NULL,
`channel_name` text,
PRIMARY KEY (`channel_snowflake`),
KEY `fk_snowflake_channel_to_server` (`server_snowflake`),
CONSTRAINT `fk_snowflake_channel_to_server` FOREIGN KEY (`server_snowflake`) REFERENCES `servers` (`server_snowflake`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- Data exporting was unselected.
-- Dumping structure for table breadbot_test.messages
CREATE TABLE IF NOT EXISTS `messages` (
`message_snowflake` bigint unsigned NOT NULL,
`channel_snowflake` bigint unsigned NOT NULL,
`user_snowflake` bigint unsigned NOT NULL,
`message_content` text NOT NULL,
`message_timestamp` datetime NOT NULL,
`message_deleted` bit(1) NOT NULL DEFAULT (0),
PRIMARY KEY (`message_snowflake`),
KEY `fk_snowflake_message_to_channel` (`channel_snowflake`),
KEY `fk_snowflake_message_to_user` (`user_snowflake`),
CONSTRAINT `fk_snowflake_message_to_channel` FOREIGN KEY (`channel_snowflake`) REFERENCES `channels` (`channel_snowflake`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `fk_snowflake_message_to_user` FOREIGN KEY (`user_snowflake`) REFERENCES `users` (`user_snowflake`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- Data exporting was unselected.
-- Dumping structure for table breadbot_test.message_attachments
CREATE TABLE IF NOT EXISTS `message_attachments` (
`attachment_snowflake` bigint unsigned NOT NULL,
`message_snowflake` bigint unsigned NOT NULL DEFAULT (0),
`attachment_name` text NOT NULL,
`attachment_description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
`attachment_timestamp` datetime NOT NULL,
`attachment_mime_type` tinytext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
`attachment_url` text NOT NULL,
`attachment_downloaded` bit(1) NOT NULL DEFAULT (0),
PRIMARY KEY (`attachment_snowflake`) USING BTREE,
KEY `fk_snowflake_messages_to_attachments` (`message_snowflake`),
CONSTRAINT `fk_snowflake_messages_to_attachments` FOREIGN KEY (`message_snowflake`) REFERENCES `messages` (`message_snowflake`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- Data exporting was unselected.
-- Dumping structure for table breadbot_test.message_content_changes
CREATE TABLE IF NOT EXISTS `message_content_changes` (
`message_change_id` int unsigned NOT NULL AUTO_INCREMENT,
`message_snowflake` bigint unsigned NOT NULL,
`message_change_old_timestamp` datetime NOT NULL,
`message_change_old_content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
PRIMARY KEY (`message_change_id`),
KEY `fk_snowflake_message_to_message_changes` (`message_snowflake`),
CONSTRAINT `fk_snowflake_message_to_message_changes` FOREIGN KEY (`message_snowflake`) REFERENCES `messages` (`message_snowflake`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- Data exporting was unselected.
-- Dumping structure for table breadbot_test.servers
CREATE TABLE IF NOT EXISTS `servers` (
`server_snowflake` bigint unsigned NOT NULL,
`server_name` text NOT NULL,
`server_description` mediumtext,
PRIMARY KEY (`server_snowflake`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- Data exporting was unselected.
-- Dumping structure for table breadbot_test.users
CREATE TABLE IF NOT EXISTS `users` (
`user_snowflake` bigint unsigned NOT NULL,
`user_name` text NOT NULL,
`user_displayname` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
PRIMARY KEY (`user_snowflake`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- Data exporting was unselected.
-- Dumping structure for table breadbot_test.winston_breadbot
CREATE TABLE IF NOT EXISTS `winston_breadbot` (
`id` int NOT NULL AUTO_INCREMENT,
`level` varchar(16) NOT NULL,
`message` varchar(2048) NOT NULL,
`meta` varchar(2048) NOT NULL,
`timestamp` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- Data exporting was unselected.
-- Dumping structure for table breadbot_test.winston_sqlutil
CREATE TABLE IF NOT EXISTS `winston_sqlutil` (
`id` int NOT NULL AUTO_INCREMENT,
`level` varchar(16) NOT NULL,
`message` varchar(2048) NOT NULL,
`meta` varchar(2048) NOT NULL,
`timestamp` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- Data exporting was unselected.
/*!40103 SET TIME_ZONE=IFNULL(@OLD_TIME_ZONE, 'system') */;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;
+35
View File
@@ -0,0 +1,35 @@
const readline = require('readline');
const r1 = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false,
});
let date1 = null;
let date2 = null;
let result = null;
r1.on('line', line => {
if (line.startsWith('date1')) {
date1 = new Date(line.split(':')[1]);
}
else if (line.startsWith('date2')) {
date2 = new Date(line.split(':')[1]);
}
else if (line.startsWith('result')) {
if (date1 !== null && date2 !== null) {
result = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate(),
date2.getHours(), date2.getMinutes(), date2.getSeconds());
console.log(result);
}
}
else {
console.log('Bad command');
}
});
r1.once('close', () => {
console.log('Closing');
});
+63
View File
@@ -0,0 +1,63 @@
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');
const getAllFiles = function(directoryPath, arrayOfFiles) {
const files = fs.readdirSync(directoryPath);
arrayOfFiles = arrayOfFiles || [];
files.forEach(file => {
if (fs.statSync(directoryPath + path.sep + file).isDirectory()) {
arrayOfFiles = getAllFiles(directoryPath + path.sep + file, arrayOfFiles);
}
else {
arrayOfFiles.push(path.join(__dirname, directoryPath, path.sep, file));
}
});
return arrayOfFiles;
};
const commands = [];
const allFiles = [];
getAllFiles('.' + path.sep + 'commands', allFiles);
allFiles.forEach(file => {
console.log(file);
});
// Grab all the command files from the commands directory you created earlier
const commandFiles = allFiles.filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const command = require(`${file}`);
if ('enabled' in command && command.enabled && 'data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
}
else {
console.log(`Skipping ${file} as it is missing one or more required exported fields`);
}
}
// Construct and prepare an instance of the REST module
const rest = new REST({ version: '10' }).setToken(token);
// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
}
catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
+1954 -3185
View File
File diff suppressed because it is too large. Load diff
+18 -14
View File
@@ -1,24 +1,28 @@
{ {
"name": "breadbot-test", "name": "breadbot",
"version": "1.0.0", "version": "1.0.0",
"main": "breadbot.ts", "description": "A very bready Discord bot",
"main": "breadbot.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1"
"dev": "tsx watch src/breadbot.ts",
"start": "node dist/breadbot.js",
"build": "tsup src/breadbot.ts --minify"
}, },
"author": "", "author": "Bradley Bickford",
"license": "ISC", "license": "ISC",
"description": "",
"dependencies": { "dependencies": {
"discord.js": "^14.20.0", "@discordjs/opus": "^0.9.0",
"dotenv": "^16.5.0", "@discordjs/voice": "^0.16.0",
"sqlite3": "^5.1.7" "@vvo/tzdb": "^6.77.0",
"discord.js": "^14.6.0",
"googleapis": "^109.0.1",
"libsodium-wrappers": "^0.7.13",
"mysql": "^2.18.1",
"mysql2": "^3.6.3",
"node-crc": "1.3.2",
"prism-media": "^2.0.0-alpha.0",
"winston": "^3.11.0",
"winston-mysql": "^1.1.1"
}, },
"devDependencies": { "devDependencies": {
"tsup": "^8.5.0", "eslint": "^8.27.0"
"tsx": "^4.20.3",
"typescript": "^5.8.3"
} }
} }
+18
View File
@@ -0,0 +1,18 @@
const mysql = require('mysql2')
const { mysql_username, mysql_password } = require('./config.json')
var connection_pool = mysql.createPool({
host: "10.26.48.207",
user: mysql_username,
password: mysql_password,
database: 'breadbot_test',
connectionLimit: 10
}).promise()
connection_pool.query("SELECT * FROM servers").then(async ([rows, fields]) => {
console.log(rows)
return await connection_pool.query("SELECT * FROM channels").then(([rows, fields]) => {
console.log(rows)
return "SOME TEXT"
})
}).catch(() => {return "SOME FAIL TEXT"}).then(console.log)
-84
View File
@@ -1,84 +0,0 @@
import { CacheType, ChatInputCommandInteraction, Client, Events, GatewayIntentBits, Guild, GuildBasedChannel, Interaction, Role } from "discord.js"
import { utilities } from "./utilties"
import { commands } from "./commands"
import { config } from "./config"
import { SQLCommon } from "./utilties/storage/interfaces"
export const client : Client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent
]
})
export let db: SQLCommon
if (config.DB_MODE == "sqlite") {
db = new utilities.sqlite.SqliteDB("breadbot_test.db")
db.run("PRAGMA foreign_keys = ON")
utilities.tables.makeTables(db)
//TODO I really don't want this to be here.
utilities.events.messages.setupMessageCapture(client, db)
utilities.events.roles.setupRoleCapture(client, db)
}
client.once(Events.ClientReady, () => {
// TODO Winston should handle this
console.log("Breadbot is ready")
client.guilds.cache.forEach(async (guild: Guild) => {
await utilities.commands.deployCommands(guild.id)
// TODO handle failures?
await utilities.guilds.insertGuild(db, guild)
guild.channels.cache.forEach(async (channel: GuildBasedChannel) => {
await utilities.channels.insertChannel(db, channel)
})
guild.roles.cache.forEach(async (role: Role) => {
await utilities.roles.insertRole(db, role)
})
})
})
client.on(Events.GuildCreate, async (guild : Guild) => {
await utilities.commands.deployCommands(guild.id)
await utilities.guilds.insertGuild(db, guild)
guild.channels.cache.forEach(async (channel: GuildBasedChannel) => {
await utilities.channels.insertChannel(db, channel)
})
})
client.on(Events.ChannelCreate, async (channel) => {
console.log("CHANNEL CREATE CALLED")
await utilities.channels.insertChannel(db, channel)
})
client.on(Events.ThreadCreate, async (channel) => {
console.log("THREAD CREATE CALLED")
console.log(channel.toString())
await utilities.channels.insertChannel(db, channel)
})
client.on(Events.InteractionCreate, async (interaction: Interaction) => {
if (!interaction.isCommand()) {
return
}
if (commands[interaction.commandName as keyof typeof commands]) {
commands[interaction.commandName as keyof typeof commands].execute(interaction as ChatInputCommandInteraction)
}
})
setInterval(async () => {
await utilities.breadthread.breadthreadProcessLocks(db, client)
}, 5000)
client.login(config.DISCORD_TOKEN)
-55
View File
@@ -1,55 +0,0 @@
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
export const enabled: boolean = true
export const data = new SlashCommandBuilder()
.setName("breadalert")
.setDescription("Controls event alerting using the Bread Alert subsystem")
.addSubcommand((subcommand) =>
subcommand
.setName("list")
.setDescription("List the current Bread Alert active alerts")
.addIntegerOption(option =>
option
.setName("count")
.setDescription("The number of future alerts to return, default 5")
.setRequired(false)
)
)
.addSubcommand(subcommand =>
subcommand
.setName("add")
.setDescription("Add a new Bread Alert")
.addStringOption(option =>
option
.setName("name")
.setDescription("The name of the event, must be unique")
.setRequired(true)
)
.addStringOption(option =>
option
.setName("date")
.setDescription("The date and time of the event in YYYY-MM-DD HH:MM:SS format")
.setRequired(true)
)
.addStringOption(option =>
option
.setName("notifications")
.setDescription("A comma separated list of time offsets that determine when to alert prior to the event")
.setRequired(false)
)
)
.addSubcommand(subcommand =>
subcommand
.setName("delete")
.setDescription("Delete a Bread Alert")
.addStringOption(option =>
option
.setName("name")
.setDescription("The name of the event to remove")
)
)
export async function execute(interaction: CommandInteraction) {
return interaction.reply("NOT IMPLEMENTED!")
}
-60
View File
@@ -1,60 +0,0 @@
import { ChannelType, ChatInputCommandInteraction, CommandInteraction, MessageFlags, SlashCommandBuilder } from "discord.js";
import { breadthreadEnsureAutoLock, breadthreadRemoveAutoLock } from "../utilties/breadbot/breadthread";
import { db } from "../breadbot";
import { timeShorthandToSeconds } from "../utilties/time/conversions";
export const enabled: boolean = true
export const data = new SlashCommandBuilder()
.setName("breadthread")
.setDescription("Manages Breadbot's extended thread features")
.addSubcommand(subcommand =>
subcommand
.setName("autolock")
.setDescription("Enables auto locking of a thread after a period of thread inactivity")
.addChannelOption(option =>
option
.setName("channel")
.setDescription("The name of the thread you want to autolock")
.addChannelTypes(
ChannelType.PublicThread,
ChannelType.PrivateThread,
ChannelType.AnnouncementThread
)
.setRequired(true)
)
.addBooleanOption(option =>
option
.setName("enable")
.setDescription("Enable or disable the auto locking")
.setRequired(true)
)
.addStringOption(option =>
option
.setName("timeinactive")
.setDescription("How long the thread needs to be inactive before locking, default is 3 days")
.setRequired(false)
)
)
export async function execute(interaction: ChatInputCommandInteraction) {
await interaction.deferReply({flags: MessageFlags.Ephemeral})
if(interaction.options.getSubcommand() === "autolock") {
if(interaction.options.getBoolean("enable")) {
await breadthreadEnsureAutoLock(
db,
interaction.options.getChannel("channel", true).id,
interaction.options.getString("timeinactive") ?? "3d"
)
} else {
await breadthreadRemoveAutoLock(
db,
interaction.options.getChannel("channel", true).id
)
}
await interaction.editReply("Autolock Action OK")
}
}
-9
View File
@@ -1,9 +0,0 @@
import * as ping from "./ping";
import * as breadalert from "./breadalert"
import * as breadthread from "./breadthread"
export const commands = {
ping,
breadalert,
breadthread
}
-11
View File
@@ -1,11 +0,0 @@
import { CommandInteraction, SlashCommandBuilder } from "discord.js"
export const enabled : boolean = true
export const data : SlashCommandBuilder = new SlashCommandBuilder()
.setName("ping")
.setDescription("Replies with Pong!")
export async function execute(interaction: CommandInteraction) {
return interaction.reply("Pong!")
}
-15
View File
@@ -1,15 +0,0 @@
import dotenv from "dotenv"
dotenv.config()
const { DISCORD_TOKEN, DISCORD_CLIENT_ID, DB_MODE } = process.env
if (!DISCORD_TOKEN || !DISCORD_CLIENT_ID || !DB_MODE) {
throw new Error("Missing environment variables")
}
export const config = {
DISCORD_TOKEN,
DISCORD_CLIENT_ID,
DB_MODE
}
-57
View File
@@ -1,57 +0,0 @@
import { timeShorthandToSeconds } from "../time/conversions";
import { SQLCommon } from "../storage/interfaces";
import { Client } from "discord.js";
export async function breadthreadLockExists(db: SQLCommon, channelId: string) : Promise<boolean> {
const queryResult: Object[] = await db.getAllParameterized(
"SELECT * FROM breadthread_autolock WHERE channel_snowflake = ?",
[channelId]
)
return queryResult.length != 0
}
export async function breadthreadEnsureAutoLock(db: SQLCommon, channelId: string, inactiveTimeUntilLocked: string) {
const timeUntilLocked = timeShorthandToSeconds(inactiveTimeUntilLocked)
if(await breadthreadLockExists(db, channelId)) {
await db.runParameterized(
"UPDATE breadthread_autolock SET inactivity_seconds = ? WHERE channel_snowflake = ?",
[timeUntilLocked, channelId]
)
} else {
await db.runParameterized(
"INSERT INTO breadthread_autolock (channel_snowflake, inactivity_seconds, locked) VALUES (?, ?, ?)",
[channelId, timeUntilLocked, 0]
)
}
}
export async function breadthreadRemoveAutoLock(db: SQLCommon, channelId: string) {
await db.runParameterized(
"DELETE FROM breadthread_autolock WHERE channel_snowflake = ?",
[channelId]
)
}
export async function breadthreadProcessLocks(db: SQLCommon, client: Client) {
const currentTimeSeconds = Math.round((new Date()).getTime() / 1000);
(await db.getAll("SELECT * FROM breadthread_autolock WHERE locked = 0")).forEach(async (row : any) => {
const channel = client.channels.cache.find(row.channel_snowflake)
if(channel?.isThread()) {
const lastMessageTime: number = Math.round(
channel.lastMessage?.createdAt.getTime() ?? 0 / 1000
)
if(lastMessageTime != 0 && currentTimeSeconds - lastMessageTime >= row.inactivity_seconds) {
await channel.setLocked(true, "Breadbot is locking this thread because the inactivity timeout was exceeded!")
await db.runParameterized(
"UPDATE breadthread_autolock SET locked = 1 WHERE locked = 0 AND channel_snowflake = ?",
[channel.id]
)
}
}
})
}
-51
View File
@@ -1,51 +0,0 @@
import { SQLCommon } from "../storage/interfaces";
import { DMChannel, GuildBasedChannel, PartialDMChannel } from "discord.js";
import { SQLResult } from "../storage/enumerations";
export async function doesChannelExistByID(db: SQLCommon, channelID: string) : Promise<boolean> {
const queryResult : Object[] = await db.getAllParameterized(
"SELECT * FROM channels WHERE channel_snowflake = ?",
[channelID]
)
return queryResult.length != 0
}
export async function doesChannelExist(db: SQLCommon, channel : GuildBasedChannel | DMChannel | PartialDMChannel) : Promise<boolean> {
const queryResult : Object[] = await db.getAllParameterized(
"SELECT * FROM channels WHERE channel_snowflake = ?",
[channel.id]
)
return queryResult.length != 0
}
export async function insertChannel(db: SQLCommon, channel: GuildBasedChannel | DMChannel | PartialDMChannel) : Promise<SQLResult> {
const alreadyExists: boolean = await doesChannelExist(db, channel)
if(alreadyExists) {
return SQLResult.ALREADYEXISTS
}
try {
if (channel.isDMBased()) {
await db.runParameterized(
"INSERT INTO channels VALUES (?, ?, ?, ?, ?)",
[channel.id, null, channel.recipient?.username, channel.isThread(), channel.isDMBased()]
)
} else {
await db.runParameterized(
"INSERT INTO channels VALUES (?, ?, ?, ?, ?)",
[channel.id, channel.guild.id, channel.name, channel.isThread(), channel.isDMBased()]
)
}
return SQLResult.CREATED
} catch (err) {
//TODO Winston should handle this
console.log("CHANNEL INSERT ERROR")
console.log(err)
return SQLResult.FAILED
}
}
-32
View File
@@ -1,32 +0,0 @@
import { REST, Routes } from "discord.js"
import { config } from "../../config"
import { commands } from "../../commands"
const commandsData = Object.values(commands)
.filter((command) => command.enabled)
.map((command) => command.data)
const rest : REST = new REST({ version: "10" }).setToken(config.DISCORD_TOKEN)
export async function deployCommands(guildId: string) {
try {
// TODO Winston should handle this
console.log(`Refreshing slash commands for ${guildId}`)
await rest.put(
Routes.applicationGuildCommands(
config.DISCORD_CLIENT_ID,
guildId
),
{
body: commandsData
}
)
// TODO Winston should handle this
console.log(`Successfully reloaded slash commands for ${guildId}`)
} catch (error) {
// TODO Winston should handle this
console.error(error)
}
}
-33
View File
@@ -1,33 +0,0 @@
import { Guild } from "discord.js";
import { SQLCommon } from "../storage/interfaces";
import { SQLResult } from "../storage/enumerations";
export async function doesGuildExist(db: SQLCommon, guild : Guild) : Promise<boolean> {
const queryResult : Object[] = await db.getAllParameterized(
"SELECT * FROM servers WHERE server_snowflake = ?",
[guild.id]
)
return queryResult.length != 0
}
export async function insertGuild(db: SQLCommon, guild: Guild) : Promise<SQLResult> {
const alreadyExists: boolean = await doesGuildExist(db, guild)
if (alreadyExists) {
return SQLResult.ALREADYEXISTS
}
try {
await db.runParameterized(
"INSERT INTO servers VALUES (?, ?, ?)",
[guild.id, guild.name, guild.description]
)
return SQLResult.CREATED
} catch (err) {
console.log("Insert Failed")
//TODO Winston should handle this
console.log(err)
return SQLResult.FAILED
}
}
-118
View File
@@ -1,118 +0,0 @@
import { Attachment, Message, OmitPartialGroupDMChannel, PartialMessage } from "discord.js";
import { SQLCommon } from "../storage/interfaces";
import { SQLResult } from "../storage/enumerations";
// TODO Do partial messages affect other functionality elsewhere?
export async function doesMessageExist(db: SQLCommon, message: OmitPartialGroupDMChannel<Message<boolean>> | PartialMessage) : Promise<boolean> {
const queryResult: Object[] = await db.getAllParameterized(
"SELECT * FROM messages WHERE message_snowflake = ?",
[message.id]
)
return queryResult.length != 0
}
export async function doesAttachmentExist(db: SQLCommon, attachment: Attachment) : Promise<boolean> {
const queryResult: Object[] = await db.getAllParameterized(
"SELECT * FROM message_attachments WHERE attachment_snowflake = ?",
[attachment.id]
)
return queryResult.length != 0
}
export async function insertMessage(db: SQLCommon, message: OmitPartialGroupDMChannel<Message<boolean>>) : Promise<SQLResult> {
const alreadyExists: boolean = await doesMessageExist(db, message)
if(alreadyExists) {
return SQLResult.ALREADYEXISTS
}
try {
await db.runParameterized(
"INSERT INTO messages VALUES (?, ?, ?, ?, ?, ?)",
[message.id, message.channel.id, message.author.id,
message.content, message.createdTimestamp, 0]
)
return SQLResult.CREATED
} catch (err) {
//TODO Winston should handle this
console.log("MESSAGE INSERTION ERROR")
console.log(err)
return SQLResult.FAILED
}
}
export async function updateMessageContentHistory(db: SQLCommon, message: OmitPartialGroupDMChannel<Message<boolean>>) : Promise<SQLResult> {
const messageIDExists: boolean = await doesMessageExist(db, message)
if(!messageIDExists) {
return SQLResult.FAILED
}
try {
console.log([message.id, message.editedTimestamp ?? message.createdTimestamp, message.content, message.id])
await db.runParameterized(
"INSERT INTO message_content_changes (message_snowflake, message_change_old_timestamp, message_change_old_content) " +
"SELECT messages.message_snowflake, message_timestamp, message_content FROM messages WHERE message_snowflake = ?;",
[message.id]
)
await db.runParameterized(
"UPDATE messages SET message_timestamp = ?, message_content = ? WHERE message_snowflake = ?;",
[message.editedTimestamp ?? message.createdTimestamp, message.content, message.id]
)
return SQLResult.UPDATED
} catch (err) {
//TODO Winston should handle this
console.log("MESSAGE MODIFY FAILED")
console.log(err)
return SQLResult.FAILED
}
}
export async function markMessageDeleted(db: SQLCommon, message: OmitPartialGroupDMChannel<Message<boolean>> | PartialMessage) : Promise<SQLResult> {
const messageIDExists: boolean = await doesMessageExist(db, message)
if(!messageIDExists) {
return SQLResult.FAILED
}
try {
await db.runParameterized(
"UPDATE messages SET message_deleted = 1 WHERE message_snowflake = ?",
[message.id]
)
return SQLResult.UPDATED
} catch (err) {
// TODO Winston should handle this
console.log(err)
return SQLResult.FAILED
}
}
export async function insertAttachment(db: SQLCommon, attachment: Attachment, message: OmitPartialGroupDMChannel<Message<boolean>> | PartialMessage) : Promise<SQLResult> {
const alreadyExists: boolean = await doesAttachmentExist(db, attachment)
if(alreadyExists) {
return SQLResult.ALREADYEXISTS
}
try {
await db.runParameterized(
"INSERT INTO message_attachments VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
[attachment.id, message.id, attachment.name, attachment.description, message.createdTimestamp,
attachment.contentType, attachment.url, 0]
)
return SQLResult.CREATED
} catch (err) {
// TODO Winston should handle this
console.log(err)
return SQLResult.FAILED
}
}
-75
View File
@@ -1,75 +0,0 @@
import { Role } from "discord.js";
import { SQLCommon } from "../storage/interfaces";
import { SQLResult } from "../storage/enumerations";
export async function doesRoleExist(db: SQLCommon, role : Role) : Promise<boolean> {
const queryResult : Object[] = await db.getAllParameterized(
"SELECT * FROM roles WHERE role_snowflake = ?",
[role.id]
)
return queryResult.length != 0
}
export async function insertRole(db: SQLCommon, role: Role) : Promise<SQLResult> {
const alreadyExists: boolean = await doesRoleExist(db, role)
if(alreadyExists) {
return SQLResult.ALREADYEXISTS
}
try {
await db.runParameterized(
"INSERT INTO roles VALUES (?, ?, ?, 0)",
[role.id, role.guild.id, role.name]
)
return SQLResult.CREATED
} catch (err) {
console.log("ROLE INSERT ERROR")
console.log(err)
return SQLResult.FAILED
}
}
export async function updateRole(db: SQLCommon, role: Role): Promise<SQLResult> {
const roleExists: boolean = await doesRoleExist(db, role)
if(!roleExists) {
return SQLResult.FAILED
}
try {
await db.runParameterized(
"UPDATE roles SET role_name = ? WHERE role_snowflake = ?",
[role.name, role.id]
)
return SQLResult.UPDATED
} catch (err) {
console.log("ROLE UPDATE FAILED")
console.log(err)
return SQLResult.FAILED
}
}
export async function markRoleDeleted(db: SQLCommon, role: Role) : Promise<SQLResult> {
const roleExists: boolean = await doesRoleExist(db, role)
if(!roleExists) {
return SQLResult.FAILED
}
try {
await db.runParameterized(
"UPDATE roles SET is_deleted = 1 WHERE role_snowflake = ?",
[role.id]
)
return SQLResult.UPDATED
} catch (err) {
console.log("ROLE DELETE FAILED")
console.log(err)
return SQLResult.FAILED
}
}
-34
View File
@@ -1,34 +0,0 @@
import { User } from "discord.js";
import { SQLCommon } from "../storage/interfaces";
import { SQLResult } from "../storage/enumerations";
export async function doesUserExist(db: SQLCommon, user: User): Promise<boolean> {
const queryResult: Object[] = await db.getAllParameterized(
"SELECT * FROM users WHERE user_snowflake = ?",
[user.id]
)
return queryResult.length != 0
}
export async function insertUser(db: SQLCommon, user: User): Promise<SQLResult> {
const alreadyExists: boolean = await doesUserExist(db, user)
if(alreadyExists) {
return SQLResult.ALREADYEXISTS
}
try {
await db.runParameterized(
"INSERT INTO users VALUES (?, ?, ?)",
[user.id, user.username, user.displayName]
)
return SQLResult.CREATED
} catch (err) {
//TODO Winston should handle this
console.log("USER INSERT ERROR")
console.log(err)
return SQLResult.FAILED
}
}
-7
View File
@@ -1,7 +0,0 @@
import * as roles from "./roles"
import * as messages from "./messages"
export const events = {
roles,
messages
}
-63
View File
@@ -1,63 +0,0 @@
import { Client, Events, Message, OmitPartialGroupDMChannel, PartialMessage } from "discord.js";
import { SQLResult } from "../storage/enumerations";
import { SQLCommon } from "../storage/interfaces";
import { insertChannel } from "../discord/channels";
import { insertUser } from "../discord/users";
import { insertAttachment, insertMessage, markMessageDeleted, updateMessageContentHistory } from "../discord/messages";
export function setupMessageCapture(client: Client, db: SQLCommon) {
client.on(Events.MessageCreate, async (message) => {
processMessageCreate(db, message)
})
client.on(Events.MessageUpdate, async (oldMessage, newMessage) => {
await processMessageModify(db, newMessage)
})
client.on(Events.MessageDelete, async (deletedMessage) => {
await processMessageDeleted(db, deletedMessage)
})
}
async function processMessageCreate(db: SQLCommon, message: OmitPartialGroupDMChannel<Message<boolean>>) {
const channelOk: SQLResult = await insertChannel(db, message.channel)
const userOk: SQLResult = await insertUser(db, message.author)
if (channelOk == SQLResult.ALREADYEXISTS || channelOk == SQLResult.CREATED ||
userOk == SQLResult.ALREADYEXISTS || userOk == SQLResult.CREATED) {
await insertMessage(db, message)
// TODO observe success of message insertion
if(message.attachments.size != 0) {
const allAttachments: void[] = message.attachments.map((attachment) => {
insertAttachment(db, attachment, message)
})
await Promise.all(allAttachments).catch((error) => {
// TODO Winston should handle this
console.log("MESSAGE ATTACHMENT INSERT ERROR")
console.log(error)
})
}
}
}
async function processMessageModify(db: SQLCommon, newMessage: OmitPartialGroupDMChannel<Message<boolean>>) {
await updateMessageContentHistory(db, newMessage)
if(newMessage.attachments.size != 0) {
const allAttachments: void[] = newMessage.attachments.map((attachment) => {
insertAttachment(db, attachment, newMessage)
})
await Promise.all(allAttachments).catch((error) => {
// TODO Winston should handle this
console.log(error)
})
}
}
async function processMessageDeleted(db: SQLCommon, deletedMessage: OmitPartialGroupDMChannel<Message<boolean>> | PartialMessage) {
await markMessageDeleted(db, deletedMessage)
}
-23
View File
@@ -1,23 +0,0 @@
import { Client, Events } from "discord.js";
import { SQLCommon } from "../storage/interfaces";
import { SQLResult } from "../storage/enumerations";
import { insertRole, markRoleDeleted, updateRole } from "../discord/roles";
import { insertGuild } from "../discord/guilds";
export function setupRoleCapture(client: Client, db: SQLCommon) {
client.on(Events.GuildRoleCreate, async (role) => {
const serverOk: SQLResult = await insertGuild(db, role.guild)
if (serverOk == SQLResult.ALREADYEXISTS || serverOk == SQLResult.CREATED) {
await insertRole(db, role)
}
})
client.on(Events.GuildRoleUpdate, async (role) => {
await updateRole(db, role)
})
client.on(Events.GuildRoleDelete, async (role) => {
await markRoleDeleted(db, role)
})
}
-21
View File
@@ -1,21 +0,0 @@
import * as commands from "./discord/commands"
import * as sqlite from "./storage/sqlite"
import * as tables from "./storage/tables"
import * as guilds from "./discord/guilds"
import * as channels from "./discord/channels"
import * as users from "./discord/users"
import * as breadthread from "./breadbot/breadthread"
import * as roles from "./discord/roles"
import { events } from "./events"
export const utilities = {
commands,
sqlite,
tables,
guilds,
channels,
users,
events,
breadthread,
roles
}
-7
View File
@@ -1,7 +0,0 @@
export enum SQLResult {
CREATED,
UPDATED,
DELETED,
ALREADYEXISTS,
FAILED
}
-7
View File
@@ -1,7 +0,0 @@
export interface SQLCommon {
run(query: string) : Promise<number>
runParameterized(query: string, parameters: any[]): Promise<number>
getAll(query: string) : Promise<Object[]>
getAllParameterized(query: string, parameters: any[]) : Promise<Object[]>
}
-68
View File
@@ -1,68 +0,0 @@
import * as sqlite3 from 'sqlite3'
import { SQLCommon } from "./interfaces"
export class SqliteDB implements SQLCommon {
private db : sqlite3.Database;
public constructor(private readonly dbName: string) {
this.db = new sqlite3.Database(this.dbName);
}
async run(query: string): Promise<number> {
return new Promise((resolve, reject) => {
this.db.run(query, function (this : sqlite3.RunResult, err: Error) {
if (err) {
// TODO Winston should handle this
console.log(err)
reject(err)
} else {
resolve(this.changes)
}
})
})
}
async runParameterized(query: string, parameters: any[]): Promise<number> {
return new Promise((resolve, reject) => {
this.db.run(query, parameters, function (this : sqlite3.RunResult, err: Error) {
if (err) {
// TODO Winston should handle this
console.log(err)
reject(err)
} else {
resolve(this.changes)
}
})
})
}
async getAll(query: string): Promise<Object[]> {
return new Promise((resolve, reject) => {
this.db.all(query, (err: Error, rows: Object[]) => {
if (err) {
// TODO Winston should handle this
console.log(err)
reject(err)
} else {
resolve(rows)
}
})
})
}
getAllParameterized(query: string, parameters: any[]): Promise<Object[]> {
return new Promise((resolve, reject) => {
this.db.all(query, parameters, (err: Error, rows: Object[]) => {
if (err) {
// TODO Winston should handle this
console.log(err)
reject(err)
} else {
resolve(rows)
}
})
})
}
}
-25
View File
@@ -1,25 +0,0 @@
import { SQLCommon } from "./interfaces";
const tables: string[] = [
"CREATE TABLE IF NOT EXISTS servers (server_snowflake bigint NOT NULL PRIMARY KEY,server_name text NOT NULL,server_description mediumtext);",
"CREATE TABLE IF NOT EXISTS channels (channel_snowflake bigint NOT NULL PRIMARY KEY,server_snowflake bigint,channel_name text,is_thread bit NOT NULL,is_dm bit NOT NULL);",
"CREATE TABLE IF NOT EXISTS users (user_snowflake bigint NOT NULL PRIMARY KEY,user_name text NOT NULL,user_displayname text);",
"CREATE TABLE IF NOT EXISTS messages (message_snowflake bigint NOT NULL PRIMARY KEY,channel_snowflake bigint NOT NULL,user_snowflake bigint NOT NULL,message_content longtext NOT NULL,message_timestamp datetime NOT NULL,message_deleted bit NOT NULL);",
"CREATE TABLE IF NOT EXISTS message_content_changes (message_change_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,message_snowflake bigint NOT NULL,message_change_old_timestamp datetime NOT NULL,message_change_old_content longtext NOT NULL);",
"CREATE TABLE IF NOT EXISTS message_attachments (attachment_snowflake bigint NOT NULL PRIMARY KEY,message_snowflake bigint NOT NULL,attachment_name text NOT NULL,attachment_description text,attachment_timestamp datetime NOT NULL,attachment_mime_type text,attachment_url text NOT NULL,attachment_downloaded bit NOT NULL);",
"CREATE TABLE IF NOT EXISTS breadthread_autolock (breadthread_autolock_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,channel_snowflake bigint NOT NULL,inactivity_seconds bigint NOT NULL,locked bit NOT NULL);",
"CREATE TABLE IF NOT EXISTS roles (role_snowflake bigint NOT NULL PRIMARY KEY,server_snowflake bigint NOT NULL,role_name text NOT NULL,is_deleted bit NOT NULL);"
]
const constraints: string[] = [
"ALTER TABLE channels ADD CONSTRAINT channels_server_snowflake_fk FOREIGN KEY (server_snowflake) REFERENCES servers (server_snowflake);"
]
export async function makeTables(db: SQLCommon): Promise<number[]> {
return Promise.all(tables.map((statement) => db.run(statement)))
}
export async function makeConstraints(db: SQLCommon): Promise<number[]> {
return Promise.all(constraints.map((statement) => db.run(statement)))
}
-22
View File
@@ -1,22 +0,0 @@
export function timeShorthandToSeconds(shorthand: string) : number {
let totalSeconds: number = 0
shorthand.split(" ").forEach((value) => {
console.log(value)
const unit: string = value.substring(value.length - 1, value.length)
if (unit == "d" || unit == "D") {
totalSeconds += Number.parseInt(value.substring(0, value.length - 1)) * 86400
} else if (unit == "h" || unit == "H") {
totalSeconds += Number.parseInt(value.substring(0, value.length - 1)) * 3600
} else if (unit == "m" || unit == "M") {
totalSeconds += Number.parseInt(value.substring(0, value.length - 1)) * 60
} else if (unit == "s" || unit == "S") {
totalSeconds += Number.parseInt(value.substring(0, value.length - 1))
} else {
console.log(`An invalid shorthand directive was sent ${value}`)
}
})
return totalSeconds
}
-25
View File
@@ -1,25 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Current File",
"request": "launch",
"mainClass": "${file}"
},
{
"type": "java",
"name": "RegexGenerator",
"request": "launch",
"mainClass": "RegexGenerator",
"projectName": "ProfanityFilter_ceb3bd68",
"args": [
"ass",
"shit"
]
}
]
}
-7
View File
@@ -1,7 +0,0 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}
-18
View File
@@ -1,18 +0,0 @@
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large. Load diff
@@ -1,32 +0,0 @@
public class ExceptionGenerator {
public static void main(String[] args) {
//position 0 should be the base word, the rest should be exceptions
String base = args[0].toLowerCase();
String prefixes = "(?<!";
String regex = RegexGenerator.regexGenerator(base);
String suffixes = "(?!";
for (int i = 1; i < args.length; i++) {
args[i] = "$" + args[i] + "$";
String prefix = args[i].toLowerCase().split(base)[0];
String suffix = args[i].toLowerCase().split(base)[1];
if (!prefix.equals("$")) {
prefixes += RegexGenerator.regexGenerator(prefix) + "|";
}
if (!suffix.equals("$")) {
suffixes += RegexGenerator.regexGenerator(suffix) + "|";
}
}
prefixes = prefixes.substring(0, prefixes.length() - 1);
suffixes = suffixes.substring(0, suffixes.length() - 1);
System.out.println(prefixes + ")" + regex + suffixes + ")");
}
}
@@ -1,75 +0,0 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class RegexGenerator {
private static Map<Character, String> dictionary;
static {
Map<Character, String> map = new HashMap<>();
map.put('a', "[a@*]");
map.put('b', "([b38]|\\\\|3)");
map.put('c', "[c(k]");
map.put('d', "[d]");
map.put('e', "[e3*]");
map.put('f', "([f]|ph)");
map.put('g', "[g]");
map.put('h', "[h]");
map.put('i', "[il1!*]");
map.put('j', "[j]");
map.put('k', "[kc]");
map.put('l', "[li]");
map.put('m', "([m]|rn)");
map.put('n', "[n]");
map.put('o', "[o0pq*]");
map.put('p', "[p]");
map.put('q', "[q]");
map.put('r', "[r]");
map.put('s', "[sz5$]");
map.put('t', "[t7+]");
map.put('u', "[uv*]");
map.put('v', "[v]");
map.put('w', "([w]|vv)");
map.put('x', "[x]");
map.put('y', "[y]");
map.put('z', "[z]");
map.put(' ', "");
map.put('1', "([1]|one)");
map.put('2', "([2]|two)");
map.put('3', "([3]|three)");
map.put('4', "([4]|four)");
map.put('5', "([5]|five)");
map.put('6', "([6]|six)");
map.put('7', "([7]|seven)");
map.put('8', "([8]|eight)");
map.put('9', "([9]|nine)");
map.put('0', "([0]|zero)");
dictionary = Collections.unmodifiableMap(map);
}
public static void main(String[] args) {
for (String s : args) {
String regex = "(\\\\b|^)";
for (char c : s.toLowerCase().toCharArray()) {
regex += dictionary.get(c) + "+[\\\\s\\\\n\\\\W]*";
}
regex += "(\\\\b|$)";
System.out.println(regex);
}
}
public static String regexGenerator(String str) {
String regex = "(\\\\b|^)";
for (char c : str.toLowerCase().toCharArray()) {
regex += dictionary.get(c) + "+[\\\\s\\\\n\\\\W]*";
}
regex += "(\\\\b|$)";
return regex;
}
}
-15
View File
@@ -1,15 +0,0 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"rootDir": "./src",
"outDir": "./dist",
"removeComments": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"strictNullChecks": true,
"skipLibCheck": true
}
}
+122
View File
@@ -0,0 +1,122 @@
const { google } = require('googleapis');
const { googlePrivateKey, googleClientEmail, googleProjectNumber } = require('../config.json');
const { stdout } = require('node:process');
const SCOPES = ['https://www.googleapis.com/auth/calendar'];
async function getCalendarReference() {
const jwtClient = new google.auth.JWT(
googleClientEmail,
'../keyfile.json',
googlePrivateKey,
SCOPES,
);
return new google.calendar({
version: 'v3',
project: googleProjectNumber,
auth: jwtClient,
});
}
async function doesCalendarExist(calendarName) {
const calendarReference = await getCalendarReference();
const listResults = await calendarReference.calendarList.list({});
for (const item of listResults.data.items) {
if (item.summary === calendarName) {
return item;
}
}
return null;
}
async function getListOfCalendars(options, callback) {
const calendarReference = await getCalendarReference();
calendarReference.calendarList.list(options, async (err, res) => {
if (err) {
callback(false, 'Failed to retrieve the list of calendars\nAsk Bradley to check Breadbot console');
stdout.write('[ERROR]:');
console.log(err.errors);
return;
}
callback(true, 'Calendar List', res.data.items);
});
}
async function addCalendar(calendarName, timezone, callback) {
const calendarReference = await getCalendarReference();
calendarReference.calendars.insert({
resource: {
summary: calendarName,
timeZone: timezone,
},
},
// eslint-disable-next-line no-unused-vars
async (err, res) => {
if (err) {
callback(false, 'Failed to create new calendar ' + calendarName + '\nAsk Bradley to check Breadbat console', err);
stdout.write('[ERROR]: ');
console.log(err.errors);
return;
}
callback(true, 'Successfully created new calendar ' + calendarName, null);
});
}
async function deleteCalendar(calendarName, callback) {
const exists = await doesCalendarExist(calendarName);
if (exists) {
const calendarReference = await getCalendarReference();
calendarReference.calendars.delete({
calendarId: exists.id,
},
// eslint-disable-next-line no-unused-vars
async (err, res) => {
if (err) {
callback(false, 'Failed to delete ' + calendarName + '\nAsk Bradley to check Breadbot console', err);
stdout.write('[ERROR]: ');
console.log(err);
return;
}
callback(true, 'Successfully deleted ' + calendarName, null);
});
}
else {
callback(false, 'The calendar name specified doesn\'t exist', null);
}
}
async function addEvent(calendarName, eventName, location, description, startDate, startTime, endDate, endTime) {
const exists = await doesCalendarExist(calendarName);
if (exists) {
const calendarReference = await getCalendarReference();
calendarReference.events.insert({
calendarId: exists.id,
resource: {
summary: eventName,
location: location,
description: description,
start: {
}
},
})
}
else {
callback(false, 'The calendar name specified doesn\'t exist', null);
}
}
module.exports = {
getCalendarReference,
getListOfCalendars,
doesCalendarExist,
deleteCalendar,
addCalendar,
};
+241
View File
@@ -0,0 +1,241 @@
const mysql = require('mysql2')
const winston = require('winston')
const winston_mysql = require('winston-mysql')
const {
mysql_username,
mysql_password,
mysql_host,
mysql_db_name,
sqlutil_logging_config
} = require('../config.json')
var connection_pool = null
var logger = null
async function buildPool() {
if (connection_pool == null) {
connection_pool = mysql.createPool({
host: mysql_host,
user: mysql_username,
password: mysql_password,
database: mysql_db_name,
connectionLimit: 10,
multipleStatements: true
}).promise()
}
if (logger == null) {
logger = winston.createLogger({
level: "silly",
transports: [
new winston.transports.Console({
format: winston.format.simple(),
level: sqlutil_logging_config["console_log_level"]
}),
new winston_mysql({
level: sqlutil_logging_config["sql_log_level"],
host: sqlutil_logging_config["mysql_host"],
user: sqlutil_logging_config["mysql_username"],
password: sqlutil_logging_config["mysql_password"],
database: sqlutil_logging_config["mysql_db_name"],
table: sqlutil_logging_config["mysql_table_name"]
})
]
})
}
}
async function registerServerIfMissing(server_snowflake, server_name, server_description) {
return connection_pool.query("SELECT * FROM servers WHERE server_snowflake = ?;", [server_snowflake]).then(async ([rows, fields]) => {
if (rows.length != 0) {
return true
} else {
return await connection_pool.query("INSERT INTO servers VALUES (?, ?, ?)", [server_snowflake, server_name, server_description]).then(([rows, fields]) => {
return true
})
}
}).catch((error) => {
logger.error(error)
return false
})
}
async function registerChannelIfMissing(channel_snowflake, server_snowflake, channel_name) {
return connection_pool.query("SELECT * FROM channels WHERE channel_snowflake = ?;", [channel_snowflake]).then(async ([rows, fields]) => {
if (rows.length != 0) {+
logger.info("Channel already registered")
return true
} else {
logger.info("Channel Not registered, registering")
return await connection_pool.query("INSERT INTO channels VALUES (?, ?, ?)", [channel_snowflake, server_snowflake, channel_name]).then(([rows, fields]) => {
return true
})
}
}).catch((error) => {
logger.error(error)
return false
})
}
async function updateMessageContentIfPresent(message_snowflake, message_content, message_timestamp) {
return connection_pool.query("SELECT message_snowflake FROM messages WHERE message_snowflake = ?", [message_snowflake]).then(async ([rows, fields]) => {
if (rows.length == 0) {
logger.info("Message specified doesn't exist, probably created before breadbot was here")
return false
} else {
return await connection_pool.query(
"INSERT INTO message_content_changes (message_snowflake, message_change_old_timestamp, message_change_old_content) " +
"SELECT message_snowflake, message_timestamp, message_content FROM messages WHERE message_snowflake = ?;" +
"UPDATE messages SET message_timestamp = ?, message_content = ? WHERE message_snowflake = ?;",
[message_snowflake, message_timestamp, message_content, message_snowflake]
).then(([rows, fields]) => {
return true
})
}
}).catch((error) => {
logger.error(error)
return false
})
}
async function markMessageDeletedIfPresent(message_snowflake) {
return connection_pool.query("SELECT message_snowflake FROM messages WHERE message_snowflake = ?", [message_snowflake]).then(async ([rows, fields]) => {
if (rows.length == 0) {
logger.info("Message specified doesn't exists, probably created before breadbot was here")
return false
} else {
return await connection_pool.query(
"UPDATE messages SET message_deleted = 1 WHERE message_snowflake = ?", [message_snowflake]
).then(([rows, fields]) => {
return true
})
}
}).catch((error) => {
logger.error(error)
return false
})
}
async function registerAttachmentIfMissing(attachment_snowflake, message_snowflake, attachment_name, attachment_description, attachment_timestamp, attachment_mime_type, attachment_url) {
return connection_pool.query("SELECT attachment_snowflake FROM message_attachments WHERE attachment_snowflake = ?", [attachment_snowflake]).then(async ([rows, fields]) => {
if (rows.length != 0) {
logger.info("Attachment alreaedy exists")
return true
} else {
return await connection_pool.query(
"INSERT INTO message_attachments (attachment_snowflake, message_snowflake, attachment_name, attachment_description, attachment_timestamp, attachment_mime_type, attachment_url) " +
"VALUES (?, ?, ?, ?, ?, ?, ?)",
[attachment_snowflake, message_snowflake, attachment_name, attachment_description, attachment_timestamp, attachment_mime_type, attachment_url]
).then(([rows, fields]) => {
return true
})
}
}).catch((error) => {
logger.error(error)
return false
})
}
async function registerUserIfMissing(user_snowflake, user_name, user_displayname) {
return connection_pool.query("SELECT * FROM users WHERE user_snowflake = ?;", [user_snowflake]).then(async ([rows, fields]) => {
if (rows.length != 0) {
return true
} else {
return await connection_pool.query("INSERT INTO users VALUES (?, ?, ?)", [user_snowflake, user_name, user_displayname]).then(([rows, fields]) => {
return true
})
}
}).catch((error) => {
logger.error(error)
return false
})
}
async function registerMessage(message_snowflake, channel_snowflake, user_snowflake, message_content, message_timestamp) {
return connection_pool.query("INSERT INTO messages VALUES (?, ?, ?, ?, ?, 0)", [message_snowflake, channel_snowflake, user_snowflake, message_content, message_timestamp]).then(([rows, fields]) => {
return true
}).catch((error) => {
logger.error(error)
return false
})
}
async function inCall(server_snowflake, channel_snowflake) {
return connection_pool.query("SELECT call_id FROM call_states WHERE server_snowflake = ? AND channel_snowflake = ? AND call_end_time IS NULL", [server_snowflake, channel_snowflake]).then(async ([rows, fields]) => {
if (rows.length == 0) {
return -1;
} else {
return rows[0].call_id
}
}).catch((error) => {
logger.error(error)
return -1;
})
}
async function registerNewCall(server_snowflake, channel_snowflake, call_start_time) {
return connection_pool.query("INSERT INTO call_states (server_snowflake, channel_snowflake, call_start_time, call_end_time, call_consolidated, call_transcribed, call_data_cleaned_up) VALUES (?, ?, ?, NULL, 0, 0, 0)", [server_snowflake, channel_snowflake, call_start_time]).then(async ([rows, fields]) => {
if (typeof rows.insertId === 'undefined') {
return -1;
} else {
return rows.insertId
}
}).catch((error) => {
logger.error(error)
return -1;
})
}
async function registerUserInCall(call_id, user_snowflake) {
return connection_pool.query("INSERT INTO call_users (call_id, user_snowflake) VALUES (?, ?)", [call_id, user_snowflake]).then(([rows, fields]) => {
return true
}).catch((error) => {
logger.error(error)
return false
})
}
async function deregisterUserInCall(call_id, user_snowflake) {
return connection_pool.query("DELETE FROM call_users WHERE call_id = ? AND user_snowflake = ?", [call_id, user_snowflake]).then(([rows, field]) => {
return true
}).catch((error) => {
logger.error(error)
return false
})
}
async function getNumberUsersInCall(call_id) {
return connection_pool.query("SELECT COUNT(call_users_id) AS users_in_call FROM call_users WHERE call_id = ?", [call_id]).then(([rows, fields]) => {
return rows[0].users_in_call
}).catch((error) => {
logger.error(error)
return -1
})
}
async function updateCallEndTime(call_id, call_end_time) {
return await connection_pool.query("UPDATE call_states SET call_end_time = ? WHERE call_id = ?", [call_end_time, call_id]).then(async ([rows, fields]) => {
return true
}).catch((error) => {
logger.error(error)
return false;
})
}
module.exports = {
buildPool,
registerMessage,
registerServerIfMissing,
registerChannelIfMissing,
registerUserIfMissing,
registerNewCall,
updateCallEndTime,
inCall,
updateMessageContentIfPresent,
markMessageDeletedIfPresent,
registerAttachmentIfMissing,
registerUserInCall,
deregisterUserInCall,
getNumberUsersInCall
}