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

Implement way to prevent /invite abuse #282

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
33 changes: 32 additions & 1 deletion src/core_modules/accept_invite.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,47 @@
#--depends-on config

from src import ModuleManager, utils
import time

SETTING = utils.BoolSetting("accept-invites",
"Set whether I accept invites")

SETTING2 = utils.BoolSetting("check-for-invite-op", "Whether I accept invites from non-chanops")

THROTTLESECS = utils.IntSetting("invite-ratelimit-time", "Amount of time to wait in between invites")

badchans = []
tocheck = []

@utils.export("botset", SETTING)
@utils.export("serverset", SETTING)
@utils.export("serverset", SETTING2)
@utils.export("serverset", THROTTLESECS)
class Module(ModuleManager.BaseModule):
def chanisbad(self, server, chan):
now = time.time()
for s, c, t in badchans:
if (s, c) == (server, chan) and (now - t) < server.get_setting("invite-ratelimit-time", 60):
return True
return False

@utils.hook("received.invite")
def on_invite(self, event):
if event["server"].is_own_nickname(event["target_user"].nickname):
if event["server"].get_setting("accept-invites",
self.bot.get_setting("accept-invites", False)):
if self.chanisbad(event["server"], event["target_channel"]):
event["server"].send_raw("NOTICE %s :Please wait a little while before inviting me again." % event["user"])
return
tocheck.append((event["target_channel"], event["server"], event["user"]))
event["server"].send_join(event["target_channel"])


@utils.hook("received.366")
def on_names(self, event):
chan = event["line"].args[1]
if chan in [c for c, s, n in tocheck if event["server"] == s] and event["server"].get_setting("check-for-invite-op", False):
n = [n for c, s, n in tocheck if (c, s) == (chan, event["server"])][0]
if not event["server"].channels.get(chan).mode_or_above(n, "o"):
event["server"].send_part(chan)
event["server"].send_raw("NOTICE %s :You must be a channel operator (+o or higher) to invite me to %s" % (n, chan))
badchans.append((event["server"], chan, time.time()))