Skip to content

Commit

Permalink
Fix bot don't reply in groups
Browse files Browse the repository at this point in the history
Signed-off-by: Kowalski Dragon (kowalski7cc) <kowalski7cc@users.noreply.github.com>
  • Loading branch information
kowalski7cc committed Oct 10, 2023
1 parent c589651 commit e44991f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/unixmib_contact_bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ def main():
distribution_lists: set[int] = set()

super_admins: list[str] = [
int(value) for value in provided_super_admins.split(",") if value.isnumeric()
int(value)
for value in provided_super_admins.split(",")
if value.isnumeric()
]

database_url = os.environ.get("DATABASE_URL", "sqlite:///unixmib_contact_bot.db")
database_url = os.environ.get(
"DATABASE_URL", "sqlite:///unixmib_contact_bot.db"
)
engine = create_engine(database_url)

Base.metadata.create_all(engine)
Expand All @@ -45,15 +49,19 @@ def main():
bot_token=api_token
) as client:

@client.on(events.NewMessage(pattern="/start"))
@client.on(
events.NewMessage(pattern="/start", func=lambda e: e.is_private)
)
async def handler(event):
await event.respond(
"""Ciao, sono il bot di contatto di UnixMiB!
Scrivi un messaggio e sarai ricontattato al più presto."""
)

@client.on(
events.NewMessage(pattern="/add_distribution_list", from_users=super_admins)
events.NewMessage(
pattern="/add_distribution_list", from_users=super_admins
)
)
async def add_distribution_list(event):
current_chat_id = event.chat_id
Expand All @@ -65,7 +73,9 @@ async def add_distribution_list(event):
f"Aggiunta lista di distribuzione {current_chat_id} con successo."
)

@client.on(events.NewMessage(pattern="[^/]"))
@client.on(
events.NewMessage(pattern="[^/]", func=lambda e: e.is_private)
)
async def handler2(event):
if event.sender.username is None:
await event.respond(
Expand Down

0 comments on commit e44991f

Please sign in to comment.