Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(federation): remove bot owner check on leavefed #343

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions anjani/plugins/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,29 +436,30 @@ async def cmd_joinfed(self, ctx: command.Context, fid: Optional[str] = None) ->
return ret

@command.filters(filters.admin_only)
async def cmd_leavefed(self, ctx: command.Context, fid: Optional[str] = None) -> str:
async def cmd_leavefed(self, ctx: command.Context) -> str:
"""Leave a federation in chats"""
chat = ctx.chat
user = ctx.msg.from_user

invoker = await chat.get_member(user.id)
if invoker.status != ChatMemberStatus.OWNER or invoker.user.id != self.bot.owner:
if invoker.status != ChatMemberStatus.OWNER:
return await self.text(chat.id, "err-group-creator-cmd")

if not fid:
return await self.text(chat.id, "fed-not-found")

exists = await self.get_fed(fid)
if not exists:
return await self.text(chat.id, "fed-invalid-id")
fed = await self.get_fed_bychat(chat.id)

if chat.id not in exists.get("chats", []):
if not fed:
return await self.text(chat.id, "fed-not-connected")

ret, _ = await asyncio.gather(
self.text(chat.id, "fed-chat-leave-info", exists["name"]),
self.db.update_one({"_id": fid}, {"$pull": {"chats": chat.id}}),
self.text(chat.id, "fed-chat-leave-info", fed["name"]),
self.db.update_one({"_id": fed["_id"]}, {"$pull": {"chats": chat.id}}),
)

if log := fed.get("log"):
await self.bot.client.send_message(
log,
f"**New Chat Joined Federation**\n**Name**: {chat.title}",
)
return ret

@command.filters(aliases=["fpromote"])
Expand Down