mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Merge branch 'master' into primo
This commit is contained in:
commit
b29165017c
5 changed files with 37 additions and 18 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -92,9 +92,6 @@ ENV/
|
||||||
|
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
# config file
|
|
||||||
royalbotconfig.py
|
|
||||||
|
|
||||||
# grandbot.py files
|
# grandbot.py files
|
||||||
diario.txt
|
diario.txt
|
||||||
|
|
||||||
|
|
21
database.py
21
database.py
|
@ -72,17 +72,12 @@ def login(username, password, enable_exceptions=False):
|
||||||
# Create a new session
|
# Create a new session
|
||||||
session = Session()
|
session = Session()
|
||||||
# Find the matching user
|
# Find the matching user
|
||||||
users = session.query(User).filter_by(username=username).all()
|
db_user = session.query(User).filter_by(username=username).first()
|
||||||
# No user with a matching username found
|
# Verify that the user exists
|
||||||
if len(users) == 0:
|
if db_user is not None:
|
||||||
if enable_exceptions:
|
|
||||||
raise NoUsersMatchingError("No users with the specified username found.")
|
|
||||||
else:
|
|
||||||
return session, None
|
return session, None
|
||||||
db_user = users[0]
|
|
||||||
# Test the password and return the session and the user if successful
|
# Test the password and return the session and the user if successful
|
||||||
if bcrypt.hashpw(password.encode("utf8"), db_user.password) == db_user.password:
|
if bcrypt.hashpw(password.encode("utf8"), db_user.password) == db_user.password:
|
||||||
# TODO: Maybe there's a better way to do this?
|
|
||||||
return session, db_user
|
return session, db_user
|
||||||
else:
|
else:
|
||||||
if enable_exceptions:
|
if enable_exceptions:
|
||||||
|
@ -94,6 +89,16 @@ def login(username, password, enable_exceptions=False):
|
||||||
def init_royal_db():
|
def init_royal_db():
|
||||||
create_user("test", "test", True)
|
create_user("test", "test", True)
|
||||||
|
|
||||||
|
|
||||||
|
def find_user(username):
|
||||||
|
"""Find the user with the specified username and return the session and the user object."""
|
||||||
|
# Create a new session
|
||||||
|
session = Session()
|
||||||
|
# Find the matching user
|
||||||
|
db_user = session.query(User).filter_by(username=username).first()
|
||||||
|
# Return the session and the user
|
||||||
|
return session, db_user
|
||||||
|
|
||||||
session = Session()
|
session = Session()
|
||||||
# Generate the database if it's empty
|
# Generate the database if it's empty
|
||||||
if session.query(User).first() is None:
|
if session.query(User).first() is None:
|
||||||
|
|
|
@ -31,7 +31,7 @@ def currently_logged_in(thing):
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
async def start_telegram(bot, update, arguments):
|
async def start_telegram(bot, update, _):
|
||||||
# Set status to typing
|
# Set status to typing
|
||||||
await update.message.chat.set_chat_action(bot, "typing")
|
await update.message.chat.set_chat_action(bot, "typing")
|
||||||
user = currently_logged_in(update)
|
user = currently_logged_in(update)
|
||||||
|
@ -614,10 +614,8 @@ Sintassi: `/toggleroyal <username>`"""
|
||||||
if len(arguments) != 1:
|
if len(arguments) != 1:
|
||||||
await update.message.reply(bot, "⚠ Sintassi del comando non valida.\n`/toggleroyal <username>`", parse_mode="Markdown")
|
await update.message.reply(bot, "⚠ Sintassi del comando non valida.\n`/toggleroyal <username>`", parse_mode="Markdown")
|
||||||
return
|
return
|
||||||
# Create a new database session
|
# Find the specified user
|
||||||
session = database.Session()
|
session, user = database.find_user(arguments[0])
|
||||||
# Find the user
|
|
||||||
user = session.query(database.User).filter_by(username=arguments[0]).first()
|
|
||||||
# Check if the user exists
|
# Check if the user exists
|
||||||
if user is None:
|
if user is None:
|
||||||
await update.message.reply(bot, "⚠ L'utente specificato non esiste.")
|
await update.message.reply(bot, "⚠ L'utente specificato non esiste.")
|
||||||
|
|
19
royalbotconfig.py
Normal file
19
royalbotconfig.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
class MissingTokenError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
if "telegram_token" in os.environ:
|
||||||
|
telegram_token = os.environ["telegram_token"]
|
||||||
|
else:
|
||||||
|
raise MissingTokenError("telegram_token")
|
||||||
|
|
||||||
|
if "discord_token" in os.environ:
|
||||||
|
discord_token = os.environ["discord_token"]
|
||||||
|
else:
|
||||||
|
raise MissingTokenError("discord_token")
|
||||||
|
|
||||||
|
if "discord_webhook" in os.environ:
|
||||||
|
discord_webhook = os.environ["discord_webhook"]
|
||||||
|
else:
|
||||||
|
raise MissingTokenError("discord_webhook")
|
|
@ -63,7 +63,7 @@ class Bot:
|
||||||
self.updates.append(Update(update))
|
self.updates.append(Update(update))
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
pass
|
pass
|
||||||
if len(data) > 0:
|
if len(self.updates) > 0:
|
||||||
self.offset = self.updates[-1].update_id + 1
|
self.offset = self.updates[-1].update_id + 1
|
||||||
|
|
||||||
async def parse_update(self, update):
|
async def parse_update(self, update):
|
||||||
|
|
Loading…
Reference in a new issue