diff --git a/Calendar/LICENSE b/Calendar/LICENSE new file mode 100644 index 00000000..ee7d6a54 --- /dev/null +++ b/Calendar/LICENSE @@ -0,0 +1,14 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. + diff --git a/Calendar/README.md b/Calendar/README.md new file mode 100644 index 00000000..4667defc --- /dev/null +++ b/Calendar/README.md @@ -0,0 +1,5 @@ +Notifies of scheduled events in iCal calendars. + +Depends on the libraries icalendar and requests. + +May limitless beings benefit. diff --git a/Calendar/__init__.py b/Calendar/__init__.py new file mode 100644 index 00000000..c9b009e1 --- /dev/null +++ b/Calendar/__init__.py @@ -0,0 +1,44 @@ +### +# 2023, Matias Wilkman +# +# +### + +""" +Calendar: Notifies of scheduled events in iCal calendars +""" + +import sys +import supybot +from supybot import world + +# Use this for the version of this plugin. +__version__ = "0.1" + +__author__ = supybot.Author('Matias Wilkman', 'appas', +'matias.wilkman@gmail.com') + +# This is a dictionary mapping supybot.Author instances to lists of +# contributions. +__contributors__ = {} + +# This is a url where the most recent plugin package can be downloaded. +__url__ = 'https://github.com/matiasw/my-limnoria-plugins/Calendar' + +from . import config +from . import plugin +from importlib import reload +# In case we're being reloaded. +reload(config) +reload(plugin) +# Add more reloads here if you add third-party modules and want them to be +# reloaded when this plugin is reloaded. Don't forget to import them as well! + +if world.testing: + from . import test + +Class = plugin.Class +configure = config.configure + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/Calendar/config.py b/Calendar/config.py new file mode 100644 index 00000000..70043a71 --- /dev/null +++ b/Calendar/config.py @@ -0,0 +1,34 @@ +### +# Copyright (c) 2023, Matias Wilkman +# All rights reserved. +# +# +### + +from supybot import conf, registry +try: + from supybot.i18n import PluginInternationalization + _ = PluginInternationalization('Calendar') +except: + # Placeholder that allows to run the plugin on a bot + # without the i18n module + _ = lambda x: x + + +def configure(advanced): + # This will be called by supybot to configure this module. advanced is + # a bool that specifies whether the user identified themself as an advanced + # user or not. You should effect your configuration by manipulating the + # registry as appropriate. + from supybot.questions import expect, anything, something, yn + conf.registerPlugin('Calendar', True) + + +Calendar = conf.registerPlugin('Calendar') +# This is where your configuration variables (if any) should go. For example: +# conf.registerGlobalValue(Calendar, 'someConfigVariableName', +# registry.Boolean(False, _("""Help for someConfigVariableName."""))) +conf.registerGlobalValue(Calendar, 'calendars', + registry.SpaceSeparatedListOfStrings("", """Determines the calendar URLs in (in ics format) to use""")) + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/Calendar/local/__init__.py b/Calendar/local/__init__.py new file mode 100644 index 00000000..e86e97b8 --- /dev/null +++ b/Calendar/local/__init__.py @@ -0,0 +1 @@ +# Stub so local is a module, used for third-party modules diff --git a/Calendar/plugin.py b/Calendar/plugin.py new file mode 100644 index 00000000..cce2536a --- /dev/null +++ b/Calendar/plugin.py @@ -0,0 +1,39 @@ +### +# 2023, Matias Wilkman +# +# +### + +from supybot import utils, plugins, ircutils, callbacks +from supybot.commands import * +from supybot.i18n import PluginInternationalization +from datetime import datetime +import icalendar +import requests + +_ = PluginInternationalization('Calendar') + +class Calendar(callbacks.Plugin): + """Notifies of scheduled events in iCal calendars""" + threaded = True + + + @wrap + def nextevent(self, irc, msg, args): + """takes no arguments + + Replies with the next event in the calendar + """ + calendar = icalendar.Calendar.from_ical(requests.get(self.registryValue("calendars")[0]).text) + for event in calendar.walk("VEVENT"): + date = icalendar.vDDDTypes.from_ical(event.get("DTSTART")) + if date > datetime.now().date(): + reply = "The next event in the calendar is {summary}, on {date}".format( + summary=event.get("SUMMARY"), + date=date.strftime("%d.%m.%Y")) + irc.reply(reply) + +Class = Calendar + + +# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/Calendar/setup.py b/Calendar/setup.py new file mode 100644 index 00000000..90b4e2cc --- /dev/null +++ b/Calendar/setup.py @@ -0,0 +1,12 @@ +### +# Copyright (c) 2023, Matias Wilkman +# All rights reserved. +# +# +### + +from supybot.setup import plugin_setup + +plugin_setup( + 'Calendar', +) diff --git a/Calendar/test.py b/Calendar/test.py new file mode 100644 index 00000000..16f52a2f --- /dev/null +++ b/Calendar/test.py @@ -0,0 +1,15 @@ +### +# Copyright (c) 2023, Matias Wilkman +# All rights reserved. +# +# +### + +from supybot.test import * + + +class CalendarTestCase(PluginTestCase): + plugins = ('Calendar',) + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: