Compare commits
4 commits
1e30e9bddc
...
36485fbda8
| Author | SHA1 | Date | |
|---|---|---|---|
| 36485fbda8 | |||
| 75dd4f796e | |||
| 6bcf41f208 | |||
| d37d773b9b |
5 changed files with 60 additions and 1 deletions
|
|
@ -13,3 +13,4 @@ dead simple last.fm bot
|
|||
- add collage generation
|
||||
- fix attachment generation and upload
|
||||
- temporary fix: upload and link to catbox urls
|
||||
- permanent fix: fork and update nerimity library
|
||||
|
|
|
|||
19
bot.py
19
bot.py
|
|
@ -7,9 +7,11 @@ import pylast
|
|||
|
||||
class Bot(nerimity.Client):
|
||||
"""Extended client class for extra functionality."""
|
||||
def __init__(self, lastfm_api_key: str, lastfm_api_secret: str, db_file: str = "database.db", *args, **kwargs):
|
||||
def __init__(self, lastfm_api_key: str, lastfm_api_secret: str, owner_id: int = None, db_file: str = "database.db", *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.owner_id = owner_id
|
||||
|
||||
# initialize last.fm client
|
||||
self.lastfm = pylast.LastFMNetwork(
|
||||
api_key = lastfm_api_key,
|
||||
|
|
@ -19,6 +21,7 @@ class Bot(nerimity.Client):
|
|||
self.db = None
|
||||
self.db_file = db_file
|
||||
|
||||
|
||||
def load_commands(self, commands_dir: str):
|
||||
for filename in os.listdir(commands_dir):
|
||||
if filename.endswith(".py") and not filename.startswith("_"):
|
||||
|
|
@ -28,6 +31,20 @@ class Bot(nerimity.Client):
|
|||
module.setup(self)
|
||||
print(f"Loaded {module_name}")
|
||||
print("Registered commands:", self.commands)
|
||||
|
||||
def is_owner(self, user: nerimity.Member = None):
|
||||
if not user: return None
|
||||
else:
|
||||
if user.id == self.owner_id: return True
|
||||
else: return False
|
||||
|
||||
def _process_slash_commands(self, message: nerimity.Message):
|
||||
if message.author.id == self.account.id: return
|
||||
super()._process_slash_commands(message)
|
||||
|
||||
async def _process_commands(self, message: nerimity.Message):
|
||||
if message.author.id == self.account.id: return
|
||||
await super()._process_commands(message)
|
||||
|
||||
async def init_db(self):
|
||||
print("Initializing database...")
|
||||
|
|
|
|||
39
commands/admin.py
Normal file
39
commands/admin.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import nerimity
|
||||
|
||||
import bot
|
||||
import utils as u
|
||||
|
||||
def setup(bot: bot.Bot):
|
||||
@bot.command(name="echo")
|
||||
async def echo(ctx: nerimity.Context, *text: str):
|
||||
print(bot.is_owner(ctx.author))
|
||||
if not bot.is_owner(ctx.author):
|
||||
print("returned")
|
||||
return
|
||||
if not text:
|
||||
await ctx.send(u.error_msg("Contents are empty."))
|
||||
return
|
||||
|
||||
try: await ctx.send(" ".join(text))
|
||||
except Exception as e:
|
||||
print(e)
|
||||
await ctx.send(u.error_msg(f"Unknown error:\n`{e}`"))
|
||||
|
||||
@bot.command(name="post")
|
||||
async def post(ctx: nerimity.Context, *text: str):
|
||||
print(bot.is_owner(ctx.author))
|
||||
if not bot.is_owner(ctx.author):
|
||||
print("returned")
|
||||
return
|
||||
if not text:
|
||||
await ctx.send(u.error_msg("Contents are empty."))
|
||||
return
|
||||
|
||||
try:
|
||||
await ctx.send(f"Creating post:\n```markdown\n{" ".join(text)}\n```")
|
||||
# post = nerimity.Post.create_post(content=" ".join(text))
|
||||
# print(post)
|
||||
await ctx.send(u.good_msg(f"Post created!!"))
|
||||
except Exception as e:
|
||||
print(e)
|
||||
await ctx.send(u.error_msg(f"Unknown error:\n`{e}`"))
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
token = "NerimityTokenHere"
|
||||
owner_id = 1234567890
|
||||
api_key = "LastFmApiKeyHere"
|
||||
api_secret = "LastFmApiSecretHere"
|
||||
|
|
|
|||
1
main.py
1
main.py
|
|
@ -9,6 +9,7 @@ with open("config.toml", "rb") as f:
|
|||
bot = bot.Bot(
|
||||
prefix = '!',
|
||||
token = config['token'],
|
||||
owner_id = config['owner_id'],
|
||||
lastfm_api_key = config['api_key'],
|
||||
lastfm_api_secret = config['api_secret']
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue