Make gifted subs threshold configurable

master
Nikola Forró 6 years ago
parent 995b014e76
commit 5b52c25aaa

@ -82,10 +82,10 @@ class DiscordClient(discord.Client):
if cmd == message.content: if cmd == message.content:
await self.send_message(message.channel, resp.format(user=message.author.mention)) await self.send_message(message.channel, resp.format(user=message.author.mention))
def _guess_gifted_subs(self, nick, time): def _guess_gifted_subs(self, nick, time, threshold):
subs = self.commands.plausible_gifted_subs(time) subs = self.commands.plausible_gifted_subs(time)
choices = {i: s['receiver'] for i, s in enumerate(subs)} choices = {i: s['receiver'] for i, s in enumerate(subs)}
guesses = fuzzywuzzy.process.extractWithoutOrder(nick, choices, score_cutoff=50) guesses = fuzzywuzzy.process.extractWithoutOrder(nick, choices, score_cutoff=threshold)
result = [] result = []
for _, score, i in guesses: for _, score, i in guesses:
days = (time - dateutil.parser.parse(subs[i]['time'])).days days = (time - dateutil.parser.parse(subs[i]['time'])).days
@ -125,8 +125,9 @@ class DiscordClient(discord.Client):
user=message.author.mention, info_channel=info_channel.mention)) user=message.author.mention, info_channel=info_channel.mention))
except discord.errors.Forbidden: except discord.errors.Forbidden:
pass pass
threshold = self.config['Discord'].getint('gifted_sub_threshold')
self.logger.info('Looking for gifted subs matching {0}'.format(message.author.display_name)) self.logger.info('Looking for gifted subs matching {0}'.format(message.author.display_name))
gifted_subs = self._guess_gifted_subs(message.author.display_name, datetime.datetime.utcnow()) gifted_subs = self._guess_gifted_subs(message.author.display_name, datetime.datetime.utcnow(), threshold)
if gifted_subs: if gifted_subs:
await self._process_gifted_subs(message.author, gifted_subs) await self._process_gifted_subs(message.author, gifted_subs)

@ -19,6 +19,7 @@ announcer = 369539730989252609
announcement_channels = 383778221004554249,352145992256061440 announcement_channels = 383778221004554249,352145992256061440
# #gifted_alerts # #gifted_alerts
gifted_sub_notice_channel = 479792436080672789 gifted_sub_notice_channel = 479792436080672789
gifted_sub_threshold = 60
[Twitter] [Twitter]
consumer_key = __TWITTER_CONSUMER_KEY__ consumer_key = __TWITTER_CONSUMER_KEY__

Loading…
Cancel
Save