Moving
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@
|
|||||||
/user.db
|
/user.db
|
||||||
*.json
|
*.json
|
||||||
*.pyc
|
*.pyc
|
||||||
|
!/main.py
|
||||||
|
|||||||
8
.idea/discord-bot.iml
generated
8
.idea/discord-bot.iml
generated
@@ -1,8 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module version="4">
|
<module version="4">
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$" />
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/audio/386629192743256065" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
||||||
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="Python 3.9 (discord-bot)" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="Python 3.9 (discord-bot)" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="PackageRequirementsSettings">
|
||||||
|
<option name="modifyBaseFiles" value="true" />
|
||||||
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -148,11 +148,11 @@ class General(commands.Cog):
|
|||||||
|
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name='Prefix',
|
name='Prefix',
|
||||||
value=
|
value=f'The current prefix for this server is {self.bot.command_prefix}',
|
||||||
f'The current prefix for this server is {self.bot.command_prefix}',
|
|
||||||
inline=True)
|
inline=True)
|
||||||
|
|
||||||
await inter.response.send_message(embed=embed)
|
logging.info(f'server prefix {self.bot.command_prefix}')
|
||||||
|
await inter.response.send_message(embed=embed, ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
def setup(bot): # an extension must have a setup function
|
def setup(bot): # an extension must have a setup function
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from disnake.ext import commands
|
|||||||
|
|
||||||
|
|
||||||
class Bot_info(commands.Cog, name='Bot Info'):
|
class Bot_info(commands.Cog, name='Bot Info'):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot: object) -> object:
|
||||||
self.bot = bot # defining bot as global var in class
|
self.bot = bot # defining bot as global var in class
|
||||||
|
|
||||||
@commands.Cog.listener() # this is a decorator for events/listeners
|
@commands.Cog.listener() # this is a decorator for events/listeners
|
||||||
|
|||||||
32
lib.py
32
lib.py
@@ -21,7 +21,12 @@ class DB:
|
|||||||
logging.error("failed to connect db", _error)
|
logging.error("failed to connect db", _error)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def work_with_db(db_func, data_turple):
|
def work_with_db(db_func: str, data_turple: tuple):
|
||||||
|
"""
|
||||||
|
Writing to db per server userinfo
|
||||||
|
:param db_func:
|
||||||
|
:param data_turple:
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
connect = sqlite3.connect('user.db')
|
connect = sqlite3.connect('user.db')
|
||||||
cursor = connect.cursor()
|
cursor = connect.cursor()
|
||||||
@@ -37,7 +42,7 @@ class DB:
|
|||||||
sqlite_insert_with_param = (f"""INSERT OR IGNORE INTO "{guild}"
|
sqlite_insert_with_param = (f"""INSERT OR IGNORE INTO "{guild}"
|
||||||
(username, userid, nick, isbot)
|
(username, userid, nick, isbot)
|
||||||
VALUES (?, ?, ?, ?)""")
|
VALUES (?, ?, ?, ?)""")
|
||||||
data_tuple = (name, userid, nick, isbot)
|
data_tuple: tuple[str, int, str, bool] = (name, userid, nick, isbot)
|
||||||
DB.work_with_db(sqlite_insert_with_param, data_tuple)
|
DB.work_with_db(sqlite_insert_with_param, data_tuple)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -61,6 +66,10 @@ class DB:
|
|||||||
|
|
||||||
|
|
||||||
class CogsPrepare:
|
class CogsPrepare:
|
||||||
|
"""
|
||||||
|
Loads, unloads Cogs files
|
||||||
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def cog_list():
|
def cog_list():
|
||||||
cogs_list = []
|
cogs_list = []
|
||||||
@@ -94,7 +103,6 @@ class Commands:
|
|||||||
if not path.isfile('prefix.json'):
|
if not path.isfile('prefix.json'):
|
||||||
with open('prefix.json', 'w+', encoding='utf-8') as f:
|
with open('prefix.json', 'w+', encoding='utf-8') as f:
|
||||||
f.write("")
|
f.write("")
|
||||||
f.close()
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def set_prefix(inter, prefix: str):
|
async def set_prefix(inter, prefix: str):
|
||||||
@@ -118,7 +126,7 @@ class Commands:
|
|||||||
parameter = None
|
parameter = None
|
||||||
try:
|
try:
|
||||||
_json = json.load(fp) # Load the custom prefixes
|
_json = json.load(fp) # Load the custom prefixes
|
||||||
except:
|
except TypeError:
|
||||||
_json = {}
|
_json = {}
|
||||||
if guild: # If the guild exists
|
if guild: # If the guild exists
|
||||||
try:
|
try:
|
||||||
@@ -129,7 +137,7 @@ class Commands:
|
|||||||
pass
|
pass
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
fp.close()
|
|
||||||
return parameter
|
return parameter
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -139,7 +147,6 @@ class Commands:
|
|||||||
_json = json.load(_f)
|
_json = json.load(_f)
|
||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
_json = {}
|
_json = {}
|
||||||
_f.close()
|
|
||||||
try:
|
try:
|
||||||
_guild = _json[f'{guild}']
|
_guild = _json[f'{guild}']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -149,10 +156,15 @@ class Commands:
|
|||||||
|
|
||||||
with open('prefix.json', 'w', encoding='utf-8') as _f:
|
with open('prefix.json', 'w', encoding='utf-8') as _f:
|
||||||
json.dump(_json, _f, indent=4)
|
json.dump(_json, _f, indent=4)
|
||||||
_f.close()
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def determine_prefix(bot, msg):
|
def determine_prefix(bot, msg):
|
||||||
|
"""
|
||||||
|
Determite perserver bot prefix
|
||||||
|
:param bot:
|
||||||
|
:param msg:
|
||||||
|
:return: prefix
|
||||||
|
"""
|
||||||
with open('prefix.json', 'r', encoding='utf-8') as fp: # Open the JSON
|
with open('prefix.json', 'r', encoding='utf-8') as fp: # Open the JSON
|
||||||
parameter: str
|
parameter: str
|
||||||
try:
|
try:
|
||||||
@@ -160,10 +172,12 @@ class Commands:
|
|||||||
_json = load(fp) # Load the custom prefixes
|
_json = load(fp) # Load the custom prefixes
|
||||||
except:
|
except:
|
||||||
_json = {}
|
_json = {}
|
||||||
|
|
||||||
if msg.guild: # If the guild exists
|
if msg.guild: # If the guild exists
|
||||||
try:
|
try:
|
||||||
parameter = _json[f"{msg.guild.id}"]["prefix"] # Read prefix from json if is setted up
|
parameter = _json[f"{msg.guild.id}"]["prefix"] # Read prefix from json if is setted up
|
||||||
except:
|
except:
|
||||||
parameter = DEFAULT_PREFIX
|
parameter = DEFAULT_PREFIX
|
||||||
print(parameter)
|
|
||||||
return parameter
|
print(parameter)
|
||||||
|
return parameter
|
||||||
|
|||||||
3
test.py
3
test.py
@@ -1,13 +1,12 @@
|
|||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import lib
|
|
||||||
|
|
||||||
import disnake
|
import disnake
|
||||||
from disnake import OptionChoice, OptionType, Option
|
from disnake import OptionChoice, OptionType, Option
|
||||||
from disnake.ext import commands
|
from disnake.ext import commands
|
||||||
|
|
||||||
|
import lib
|
||||||
|
|
||||||
bot_owner = 386629192743256065
|
bot_owner = 386629192743256065
|
||||||
lib.Commands.check_json()
|
lib.Commands.check_json()
|
||||||
|
|||||||
Reference in New Issue
Block a user