working alpha ver.

This commit is contained in:
2025-11-21 14:43:22 -07:00
parent 73c95f8019
commit e3ece13c9b
3 changed files with 72 additions and 11 deletions

View File

@@ -2,4 +2,4 @@ compose_up:
docker compose up --build docker compose up --build
run: run:
python src/bot_core.py database.ini discord.token 477298331777761280 1441505246818996445 python src/bot_core.py database.ini discord.token 1128111628471255050 1441504341797371996

View File

@@ -2,13 +2,15 @@
import argparse import argparse
import discord import discord
import datetime
import psycopg2
from discord.ext import commands from discord.ext import commands
import helper.db_helper import helper.db_helper
CONTRASTELLAR = 181187505448681472 CONTRASTELLAR = 181187505448681472
VERYBADSTAR_PL = 1439484001751404554 VERYBADSTAR_PL = 1439484001751404554
DATABASE_CONN = helper.db_helper.DBHelper = None DATABASE_CONN: helper.db_helper.DBHelper = None
# instance variables # instance variables
larboard = 0 larboard = 0
@@ -37,9 +39,11 @@ parser.add_argument('channel_id')
@client.event @client.event
async def on_ready(): async def on_ready():
await client.tree.sync()
print(f'{client.user} has connected.') print(f'{client.user} has connected.')
print(f'we are using the guild {args.guild_id} and channel {args.channel_id}') print(f'we are using the guild {args.guild_id} and channel {args.channel_id}')
#guild: discord.Guild = await client.fetch_guild(args.guild_id)
#channel: discord.TextChannel = await client.fetch_channel(args.channel_id)
#await channel.send("test")
@client.tree.command() @client.tree.command()
@@ -52,15 +56,39 @@ async def ping(interaction: discord.Interaction):
async def on_reaction_add(react: discord.Reaction, user: discord.User): async def on_reaction_add(react: discord.Reaction, user: discord.User):
message: discord.Message = react.message message: discord.Message = react.message
reaction: discord.Reaction = react.emoji reaction: discord.Reaction = react.emoji
link: str = react.message.jump_url
react_uid: int = react.emoji.id
message_uid: int = message.id message_uid: int = message.id
if react_uid != VERYBADSTAR_PL:
if reaction != VERYBADSTAR_PL:
print(f'disregarding reaction!')
return return
is_message_in_table: bool = DATABASE_CONN.is_message_in_table(message_uid)
if react_uid == VERYBADSTAR_PL and not is_message_in_table:
print(f'adding to table /w one react')
DATABASE_CONN.add_message_to_table(message_uid=message_uid)
return
elif react_uid == VERYBADSTAR_PL and is_message_in_table:
print(f'adding one react')
current_num_reacts: int = DATABASE_CONN.num_reacts(message_uid)
DATABASE_CONN.add_one_to_message(message_uid, current_num_reacts)
current_num_reacts: int = DATABASE_CONN.num_reacts(message_uid)
if current_num_reacts == 3:
embed = discord.Embed(description=f"{react.message.content}\n[Jump to message]({link})",
timestamp=datetime.datetime.now())
embed.set_author(name=f"{react.message.author}")
posting_channel: discord.TextChannel = await client.fetch_channel(args.channel_id)
await posting_channel.send(embed=embed)
return return
# --- end commands # --- end commands

View File

@@ -53,8 +53,41 @@ class DBHelper():
def __del__(self): def __del__(self):
pass pass
def num_reacts(self, message_uid: int): def num_reacts(self, message_uid: int) -> int:
self.__CONN = connect_config(self._config) self.__CONN = connect_config(self._config)
cursor = self.__CONN.cursor() cursor = self.__CONN.cursor()
cursor.execute('SELECT ')
return cursor.execute(f'SELECT number_reacts from messages WHERE message_uid = {message_uid};')
return_val: list = cursor.fetchone()
return return_val[0]
def is_message_in_table(self, message_uid: int) -> bool:
self.__CONN = connect_config(self._config)
cursor = self.__CONN.cursor()
cursor.execute(f'SELECT * FROM messages WHERE message_uid = {message_uid};')
list_of_return = cursor.fetchone()
return list_of_return is not None
def add_message_to_table(self, message_uid: int) -> bool:
self.__CONN = connect_config(self._config)
cursor = self.__CONN.cursor()
cursor.execute(f"INSERT INTO messages (message_uid, number_reacts) VALUES ('{message_uid}', 1);")
self.__CONN.commit()
return True
def add_one_to_message(self, message_uid: int, current_count: int) -> bool:
self.__CONN = connect_config(self._config)
cursor = self.__CONN.cursor()
cursor.execute(f"UPDATE messages SET number_reacts = {current_count + 1} WHERE message_uid = {message_uid}")
self.__CONN.commit()
return True