added modifications

This commit is contained in:
thom2305 2025-04-28 19:40:03 -04:00
parent 0b10c84f90
commit 21ee8b290e
No known key found for this signature in database
GPG Key ID: 0171038FEE1BEF12
4 changed files with 105 additions and 104 deletions

42
LICENSE
View File

@ -1,21 +1,21 @@
MIT License MIT License
Copyright (c) 2025 WiiMart Copyright (c) 2025 WiiMart
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.

146
README.md
View File

@ -1,73 +1,73 @@
# WiiMart Discord Bot # WiiMart Discord Bot
<img src="https://wiimart.github.io/media/branding-bag-no-bg.png" width="100" height="100" align="right" /> <img src="https://wiimart.github.io/media/branding-bag-no-bg.png" width="100" height="100" align="right" />
This is a Discord bot built using the `discord.py` library that provides functionalities for managing and querying error codes related to a specific service. The bot can respond to commands, check the status of a service, and manage error codes stored in a SQLite database. This is a Discord bot built using the `discord.py` library that provides functionalities for managing and querying error codes related to a specific service. The bot can respond to commands, check the status of a service, and manage error codes stored in a SQLite database.
## Features ## Features
- Query error messages based on error codes. - Query error messages based on error codes.
- Set and unset the bot's status. - Set and unset the bot's status.
- Check the status of a service. - Check the status of a service.
- Uses SQLite for storing error codes and messages. - Uses SQLite for storing error codes and messages.
- Uses MySQL for managing friend codes. - Uses MySQL for managing friend codes.
## Requirements ## Requirements
- Python 3.8 or higher - Python 3.8 or higher
- `discord.py` library - `discord.py` library
- `python-dotenv` for environment variable management - `python-dotenv` for environment variable management
- `requests` for making HTTP requests - `requests` for making HTTP requests
- SQLite for database management (for error codes) - SQLite for database management (for error codes)
- MySQL connector for managing friend codes - MySQL connector for managing friend codes
## Installation ## Installation
1. **Clone the repository**: 1. **Clone the repository**:
`git clone https://github.com/WiiMart/WiiMartBot.git` `git clone https://github.com/WiiMart/WiiMartBot.git`
`cd WiiMartBot` `cd WiiMartBot`
2. **Install the required packages**: 2. **Install the required packages**:
`pip install discord.py python-dotenv requests mysql-connector-python` `pip install discord.py python-dotenv requests mysql-connector-python`
3. **Create a `.env` file** in the root directory of your project with the following format: 3. **Create a `.env` file** in the root directory of your project with the following format:
``` ```
token=your token here token=your token here
status="Not Set" status="Not Set"
mqlu=mysqluser mqlu=mysqluser
mqlp=mysqlpassword mqlp=mysqlpassword
mqld=mysqldb mqld=mysqldb
mqur=mysqlurl mqur=mysqlurl
mqpo=mysqlport mqpo=mysqlport
``` ```
## Usage ## Usage
1. **Run the bot**: 1. **Run the bot**:
`python bot.py` `python bot.py`
2. **Commands**: 2. **Commands**:
- `/status`: Check the current status of the service. - `/status`: Check the current status of the service.
- `/setstatus <status>`: Set the current status of the bot (requires Admin role). - `/setstatus <status>`: Set the current status of the bot (requires Admin role).
- `/unsetstatus`: Unset the current status of the bot (requires Admin role). - `/unsetstatus`: Unset the current status of the bot (requires Admin role).
- `/error <error_code>`: Get the error message linked with the specified error code. - `/error <error_code>`: Get the error message linked with the specified error code.
- `/addfc <fc>`: Adds your friend code to the lists of friendcodes. - `/addfc <fc>`: Adds your friend code to the lists of friendcodes.
- `/forceaddfc <user> <fc>`: Adds the users friendcode to the lists of friendcodes (requires Admin role). - `/forceaddfc <user> <fc>`: Adds the users friendcode to the lists of friendcodes (requires Admin role).
- `/getfc <user>`: Gets the friend code of the specified user. - `/getfc <user>`: Gets the friend code of the specified user.
## Database Management ## Database Management
The bot uses a SQLite database to store error codes and their corresponding messages. The database is created and populated automatically when the bot starts. The bot uses a SQLite database to store error codes and their corresponding messages. The database is created and populated automatically when the bot starts.
The MySQL database is to store friend codes from users. It is not automatically populated, a table with usersfc is needed, with 2 collums, one for the userid as varchar of 20 and one for their friend code as fc as a varcahr of 16. The MySQL database is to store friend codes from users. It is not automatically populated, a table with usersfc is needed, with 2 collums, one for the userid as varchar of 20 and one for their friend code as fc as a varcahr of 16.
### Error Codes Format ### Error Codes Format
The error codes are defined in the script and can include: The error codes are defined in the script and can include:
- Standalone codes (e.g., `204013`) - Standalone codes (e.g., `204013`)
- Ranges (e.g., `204019-204041`), which will be expanded into individual codes. - Ranges (e.g., `204019-204041`), which will be expanded into individual codes.
- Wildcard codes (e.g., `2056XX`), which can match multiple codes. - Wildcard codes (e.g., `2056XX`), which can match multiple codes.
*WiiMart is not affiliated with Nintendo or any related parties.* *WiiMart is not affiliated with Nintendo or any related parties.*
*To contact, please send an email to support@wiimart.org* *To contact, please send an email to support@wiimart.org*

13
bot.py
View File

@ -8,6 +8,7 @@ import logging
import os import os
import sqlite3 import sqlite3
import mysql.connector import mysql.connector
import sys
from discord.ext import commands from discord.ext import commands
from mysql.connector import Error from mysql.connector import Error
from dotenv import load_dotenv from dotenv import load_dotenv
@ -19,7 +20,7 @@ class ColoredFormatter(logging.Formatter):
"""Adds colors to log levels""" """Adds colors to log levels"""
COLORS = { COLORS = {
'DEBUG': Fore.CYAN, 'DEBUG': Fore.CYAN,
'INFO': Fore.GREEN, 'INFO': Fore.BLUE,
'WARNING': Fore.YELLOW, 'WARNING': Fore.YELLOW,
'ERROR': Fore.RED, 'ERROR': Fore.RED,
'CRITICAL': Fore.RED + Style.BRIGHT 'CRITICAL': Fore.RED + Style.BRIGHT
@ -33,10 +34,10 @@ class ColoredFormatter(logging.Formatter):
# Your original config with colors added # Your original config with colors added
logging.basicConfig( logging.basicConfig(
level=logging.INFO, level=logging.DEBUG,
format='%(levelname)s at %(asctime)s : %(message)s', format='%(levelname)s at %(asctime)s : %(message)s',
datefmt='%H:%M:%S', datefmt='%H:%M:%S',
handlers=[logging.StreamHandler()] handlers=[logging.StreamHandler(sys.stderr)]
) )
# Apply the colored formatter # Apply the colored formatter
@ -52,7 +53,7 @@ for handler in logger.handlers:
TAILSCALE_IP1 = "100.118.134.32" TAILSCALE_IP1 = "100.118.134.32"
TAILSCALE_IP2 = "100.95.192.63" TAILSCALE_IP2 = "100.95.192.63"
LOCK_PORT = 30000 LOCK_PORT = 30000
TIMEOUT = 5.0 TIMEOUT = 5.0
CHECK_INTERVAL = 10 CHECK_INTERVAL = 10
@ -110,7 +111,7 @@ class LeaderElection:
try: try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(TIMEOUT) s.settimeout(TIMEOUT)
s.connect((TAILSCALE_IP1, LOCK_PORT)) s.connect((TAILSCALE_IP2, LOCK_PORT))
return True return True
except (ConnectionRefusedError, socket.timeout, OSError): except (ConnectionRefusedError, socket.timeout, OSError):
return False return False
@ -130,7 +131,7 @@ def health_check(leader_election):
try: try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(TIMEOUT) s.settimeout(TIMEOUT)
s.connect((TAILSCALE_IP2, LOCK_PORT)) s.connect((TAILSCALE_IP1, LOCK_PORT))
except: except:
# Lost leadership # Lost leadership
#print("Lost leadership") #print("Lost leadership")

View File

@ -1,5 +1,5 @@
discord.py discord.py
dotenv dotenv
requests requests
sqlite3 sqlite3
colorama colorama