From 957763213039602596f4b1ee962b8c6a1cf24d49 Mon Sep 17 00:00:00 2001 From: Someone Date: Wed, 8 Dec 2021 19:38:38 +0100 Subject: [PATCH] [somebot] /course-is-meh --- modules/CommandCourseIsMeh.py | 78 +++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 modules/CommandCourseIsMeh.py diff --git a/modules/CommandCourseIsMeh.py b/modules/CommandCourseIsMeh.py new file mode 100644 index 0000000..2a8440a --- /dev/null +++ b/modules/CommandCourseIsMeh.py @@ -0,0 +1,78 @@ +# Mattermost Bot module. +# Copyright (c) 2016-2021 by Someone (aka. Jan Vales ) +# published under MIT-License +# +# This command relies on the priviledged DB-Cleaner maint script. + + +from inspect import cleandoc + +import logging +logger = logging.getLogger(__name__) + + +# pylint: disable=wrong-import-position +from AbstractCommand import AbstractCommand +class CommandCourseIsMeh(AbstractCommand): + TRIGGER = "course-is-meh" + CONFIG = {"display_name": "somebot-command", "auto_complete": True, + "auto_complete_hint": "[]", + } + CONFIG["auto_complete_desc"] = CONFIG["description"] = "Use in a course channel. Increments the 'course is meh atm' counter. The optional reason is sent to fsinf to look into." + + + def __init__(self, team_id, datadir): + super().__init__(team_id) + self.datadir = datadir + self.course_stats = dict() + + + def on_POST(self, request, data): + msg_text = data['text'].strip() + c = self.bot.api.get_channel(data["channel_id"]) + import pprint + pprint.pprint(c) + + if c["name"] in ["town-square", "off-topic"] or c["display_name"][0] == "=" or c["type"] != "O": + request.cmd_respond_text_temp("``/"+self.TRIGGER+"`` failed: Command must be used in a course channel.") + return + + if len(msg_text) > 5000: + request.cmd_respond_text_temp("``/"+self.TRIGGER+"`` failed: reason-text must be smaller than 5000 characters :(\nYour text is: "+str(len(msg_text[1]))+" characters long.") + return + + # do actual action + self.meh_courses_inc(data["channel_name"]) + if len(msg_text) > 0: + self.bot.api.create_post("cmr1s9d6678e7y94iw3jgwte3c", "``AUTODELETE-DAY`` ``/"+self.TRIGGER+"`` used by ``@"+data["user_name"]+"`` in ``"+data["team_domain"]+"::"+data["channel_name"]+"``\n```\n"+data["text"].strip()+"\n```") + + #self.bot.debug_chan("``/"+self.TRIGGER+" "+data["text"].strip()+"`` used by ``@"+data["user_name"]+"`` in ``"+data["team_domain"]+"::"+data["channel_name"]+"``") + request.cmd_respond_text_temp("### ``Done.`` :)") + + + def on_shutdown(self): + self.meh_courses_dumpstats() + + def on_SIGUSR1(self, sigusr1_cnt): + self.meh_courses_dumpstats() + + + def meh_courses_inc(self, course, amount=1): + if course in self.course_stats: + self.course_stats[course] += amount + else: + self.course_stats[course] = amount + + + def meh_courses_dumpstats(self): + stats = self.course_stats.copy() + self.course_stats = dict() + self.bot.dump_stats_json(stats, self.datadir+"course_stats-"+self.TEAM_ID+".json", cleandoc(""" + This week's ``/course-is-meh`` -stats #mmstats. + Use this command in a course channel to increment the counter if the course is currently suboptimal for you. This command produces no output in that channel. + It doesnt really matter if its because you forgot your laptop-charger or the course just changed its modalities and you turned negative without any way to become positive again. + If you supply a reason it will be forwarded to fsinf to take a look at. (We want to know when you forgot your laptop chargers! XD ) + + |course|meh-ness| + |---|---:| + """)) -- 2.43.0