Skip to content
This repository was archived by the owner on Dec 22, 2023. It is now read-only.

Commit 27bb8fd

Browse files
committed
Merge branch 'main' of https://github.com/Descended/MaplestoryDiscBot into main
2 parents a5fad28 + 9077bf6 commit 27bb8fd

File tree

12 files changed

+465
-290
lines changed

12 files changed

+465
-290
lines changed

.gitignore

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,62 @@
1-
2-
*.pyc
1+
# Desc:
2+
#*.pyc
33
src/command_logs
44
.idea/
5+
6+
# KOOKIIE:
7+
# Byte-compiled / optimized / DLL files
8+
__pycache__/
9+
*.py[cod]
10+
*$py.class
11+
12+
# C extensions
13+
*.so
14+
15+
# Distribution / packaging
16+
.Python
17+
build/
18+
develop-eggs/
19+
dist/
20+
downloads/
21+
eggs/
22+
.eggs/
23+
lib/
24+
lib64/
25+
parts/
26+
sdist/
27+
var/
28+
wheels/
29+
pip-wheel-metadata/
30+
share/python-wheels/
31+
*.egg-info/
32+
.installed.cfg
33+
*.egg
34+
MANIFEST
35+
36+
# PyInstaller
37+
# Usually these files are written by a python script from a template
38+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
39+
*.manifest
40+
*.spec
41+
42+
# Installer logs
43+
pip-log.txt
44+
pip-delete-this-directory.txt
45+
46+
# Unit test / coverage reports
47+
htmlcov/
48+
.tox/
49+
.nox/
50+
.coverage
51+
.coverage.*
52+
.cache
53+
nosetests.xml
54+
coverage.xml
55+
*.cover
56+
*.py,cover
57+
.hypothesis/
58+
.pytest_cache/
59+
60+
# Translations
61+
*.mo
62+
*.pot

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ you agree to retain the names of the authors and contributors (hereafter referre
44
to as "the list") laid out as part of the "!credits" command (hereafter referred
55
to as "the command"), as well as the command itself. You may append new
66
contributors to the list, following addition of new features. You may append new
7-
authours to the list, following transformative changes to the software.
8-
You may neither remove existing names from the list, nor the command.
7+
authors to the list, following transformative changes to the software.
8+
You may neither remove existing names from the list, nor the command itself.
99
You may not restrict users' access to the command.
1010

1111
GNU AFFERO GENERAL PUBLIC LICENSE

README.md

Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,87 +5,38 @@
55
MaplestoryDiscBot is a Python-based Discord Bot designed for MapleStory private servers.
66

77
This bot allows direct access to and/or manipulation of data via the database, as well as through web-requests (proprietary API).
8+
9+
#### Current Version: v0.2.0 Alpha [(Change Log)](changelog.md)
810

911
## SETUP
10-
### Generate Token
11-
#### Creating a New Discord Application/Bot:
12-
- Visit the [Discord Developer Portal](https://discord.com/developers/applications).
13-
- Login (if applicable).
14-
- Click on the `New Application` button, at the top right of the page.
15-
- Enter your desired application name.
16-
- Make sure the new application that you've just created is currently selected (which should automatically be the case)
17-
- Select `Bot` in the left side-panel.
18-
- Click on the `Add Bot` button (under the `Build-A-Bot` section), at the top right of the page.
19-
- Under `Token`, click on the `Copy` button to have it added to your clipboard. :octocat:
20-
### Configure Bot
21-
Configuration file path: `src/settings/Config.py`
22-
- The config file has all the required fields marked out as `REQUIRED`.
23-
- The config file has all its fields explained with comments.
12+
For the set-up guide refer to the project [wiki](https://github.com/Descended/MaplestoryDiscBot/wiki/Setup)
2413

25-
**NOTE:** This bot assumes that it is run on the same machine as the private server & its database.
26-
- This behaviour may be altered in the config file as well.
2714
## Features
15+
For full list of commands and how to use them, refer to the project [wiki](commands)
2816
### General Commands
2917
- Display help page
30-
- `!help` or `!commands`
3118
- Display character info
32-
- `!character` or `!char` or `!player`
3319
- Display guild info
34-
- `!guild` or `!guildinfo`
3520
- Display ranking
36-
- `!rankings` or `!ranking` or `!ranktop`
3721
- Display online players
38-
- `!online`
3922
- Display credits
40-
- `!credits` or `!credit`
23+
- Display server info
4124

4225
### Admin Commands
43-
- Transfer items
44-
- `!duey` or `!giveitem`
4526
- Disconnect player
46-
- `!dc`
4727
- Whisper to player in-game
48-
- `!whisper` or `!msg`
4928
- Post in-game notice
50-
- `!notice`
5129
- Unban player in-game
52-
- `!unban` or `!pardon`
5330
- Promote player to GM in-game
54-
- `!setgmlevel` or `!makegm`
5531

5632
## Gallery
5733
*Images pending. To be appended when RC1 is ready.*
58-
## Miscellaneous
59-
### Technical Details
60-
##### Current Version: v0.0.15 Alpha
61-
Changelog: [changelog.md](changelog.md)
62-
63-
| | Targeted | Tested |
64-
|---|---|---|
65-
| Python | 3.6 | ? |
66-
67-
### Auto-launch:
68-
Run the batch file `start.bat`
69-
70-
---
71-
### Manual launch:
72-
#### Option A: Using the virtual environment
73-
The virtual environment is part of the repository (as of time of writing).
74-
You may use it after cloning without needing to set it up yourself.
75-
##### Command Prompt route:
76-
- Activate the virtual environment using `call venv\scripts\activate.bat`
77-
- Note: You can deactivate the venv by using the command deactivate
78-
- Use the command `venv\scripts\python src/Main.py` to run
79-
##### PowerShell route:
80-
- Activate the virtual environment using `venv\scripts\activate`
81-
- Note: You can deactivate the venv by using the command deactivate
82-
- Use the command `venv\scripts\python src/Main.py` to run
83-
84-
85-
#### Option B: Using the global environment
86-
- `python src/Main.py`
8734

8835
---
8936

9037
### Notes prior to use
91-
Please read the license agreement prior to use, since the act of using this software implies agreement to the license. Note in particular the opening statement, as well as Section 13 of the AGPL license.
38+
Please read the license agreement prior to use, since the act of using this software implies agreement to the license. Note in particular the opening statement, as well as Section 13 of the AGPL license.
39+
40+
---
41+
## CREDITS
42+
**BIG BIG BIG THANKS TO ASURA! (@Asura#6332 on Discord)**

changelog.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,24 @@
5858
- Added change log
5959
## v0.0.15 Alpha
6060
- Updated batch file to allow venv
61-
- Added details to `features` segment of README
61+
- Added details to `features` segment of README
62+
## v0.0.16 Alpha
63+
- Added `get_gm_level(name)` utility function
64+
- Fixed `set_gm_level(name, level)` utility function
65+
- Added command for awarding vote points
66+
- Migrated repository (Raise **Minor** version number to "1")
67+
- Old commit links (from before this point) are officially dead
68+
## v0.1.0 Alpha
69+
[More code documentation, and removed desc's weird use of for loops](https://github.com/Descended/MaplestoryDiscBot/commit/e26b3bc86523085be9c1a07ec3651f18dd8ac68e)
70+
- Documentation refactoring (shifted some contents of the README to the Wiki)
71+
- Code optimisation (by removing unnecessary `for` loops)
72+
## v0.2.0 Alpha
73+
[some bot updates](https://github.com/Descended/MaplestoryDiscBot/commit/f079569dd8b16cd079fe48c60d78f954c974155e)
74+
[added the ability for the bot to restart on crash](https://github.com/Descended/MaplestoryDiscBot/commit/ab77c8a53a21acf40572139550b7806ad6bff267)
75+
[Bot updates](https://github.com/Descended/MaplestoryDiscBot/commit/ba38ffc0e6d6abeb81362d397d022cd17707bf65)
76+
[set add_role to False as default](https://github.com/Descended/MaplestoryDiscBot/commit/59805a7a9e8a03a50879245d1f9736e59840f151)
77+
[added info command to list of commands to log](https://github.com/Descended/MaplestoryDiscBot/commit/c53f374f9ee79115303f2e8cb591229ba758b1fc)
78+
- Added logic for `!info` command
79+
- Added logic for auto-restart (turned off by default)
80+
- Added logic for role-assignment (gateway intents MUST be enabled as of discord.py v1.5 and later)
81+
- Documentation updates

src/ApiHandler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44

55
class API:
6+
"""
7+
Static class that handles all requests to API server
8+
"""
69

710
@staticmethod
811
def get_server_info():

src/DatabaseHandler.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import mysql.connector
2-
import requests
32

43
from src.settings import Config
54

65

76
class DatabaseHandler:
7+
"""
8+
Static class that handles all requests/calls to Database
9+
"""
810

911
@staticmethod
1012
def get_character_stats(character_name):
@@ -128,6 +130,11 @@ def unban_account(name):
128130

129131
@staticmethod
130132
def get_rankings(category):
133+
"""
134+
Given a SQL Column (i.e. mesos, nx), order it Descending (Greatest to Least) and return the list
135+
category: string
136+
Return: dict, boolean
137+
"""
131138
try:
132139
con = mysql.connector.connect(host=Config.DATABASE_HOST, user=Config.DATABASE_USER,
133140
password=Config.DATABASE_PASS, database=Config.DATABASE_NAME)
@@ -181,7 +188,8 @@ def get_gm_level(name):
181188
password=Config.DATABASE_PASS, database=Config.DATABASE_NAME)
182189
cursor = con.cursor(dictionary=True)
183190
cursor.execute(
184-
f"SELECT gm from characters WHERE name = '{name}'") # selects gm level, most sources only have it so the characters are gm and not the accounts change this if ur source has account wide gm
191+
f"SELECT gm from characters WHERE name = '{name}'")
192+
# selects gm level, most sources only have it so the characters are gm and not the accounts change this if ur source has account wide gm
185193
rows = cursor.fetchall()
186194
if len(rows) == 0: # checks if character exists
187195
return False
@@ -202,7 +210,8 @@ def set_gm_level(name, level):
202210
con = mysql.connector.connect(host=Config.DATABASE_HOST, user=Config.DATABASE_USER,
203211
password=Config.DATABASE_PASS, database=Config.DATABASE_NAME)
204212
cursor = con.cursor(dictionary=True)
205-
cursor.execute(f"UPDATE characters SET gm = {level} where name = '{name}'") # updates gm level, most sources only have it so the characters are gm and not the accounts change this if ur source has account wide gm
213+
cursor.execute(f"UPDATE characters SET gm = {level} where name = '{name}'")
214+
# updates gm level, most sources only have it so the characters are gm and not the accounts change this if ur source has account wide gm
206215
con.commit() # commits all changes to the database
207216
con.disconnect()
208217
return f"Successfully gave GM level {level} to: {name}"

src/Main.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
from os import path
3+
34
# Necessary to run from a batch file unfortunately
45
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
56

@@ -12,7 +13,10 @@
1213

1314
start_time = time.time()
1415

15-
client = commands.Bot(command_prefix=Config.PREFIX)
16+
intents = discord.Intents.default()
17+
intents.members = True
18+
19+
client = commands.Bot(command_prefix=Config.PREFIX, intents=intents)
1620

1721

1822
@client.event
@@ -23,6 +27,14 @@ async def on_ready(): # method that is called when bot is online
2327
await client.change_presence(activity=discord.Game(name=Config.BOT_STATUS))
2428

2529

30+
@client.event
31+
async def on_member_join(member): # method that is called when a member joins the discord server
32+
if Config.ADD_ROLE:
33+
role = discord.utils.get(member.guild.roles, name=Config.ROLE_TO_GIVE)
34+
print(member.name + " has joined the discord server")
35+
await member.add_roles(role)
36+
37+
2638
@client.event
2739
async def on_message(ctx): # method that is called whenever a message is sent into discord server
2840
await CommandHandler.handle_commands(client, ctx)

src/Utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ def get_giveaway_info():
3232

3333
@staticmethod
3434
def is_command(cmd):
35+
"""
36+
Checks if a given string is a command the bot has.
37+
Is used to check whether to log a command in command_log.txt
38+
cmd: string
39+
Return: boolean
40+
"""
3541
for command in Config.COMMANDS:
3642
if cmd == Config.PREFIX + command:
3743
return True

0 commit comments

Comments
 (0)