Skip to content

Commit

Permalink
initial commit of calendar plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasw committed Sep 24, 2023
1 parent 8bc582f commit de8ac7a
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Calendar/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

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.

5 changes: 5 additions & 0 deletions Calendar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Notifies of scheduled events in iCal calendars.

Depends on the libraries icalendar and requests.

May limitless beings benefit.
44 changes: 44 additions & 0 deletions Calendar/__init__.py
Original file line number Diff line number Diff line change
@@ -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:
34 changes: 34 additions & 0 deletions Calendar/config.py
Original file line number Diff line number Diff line change
@@ -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:
1 change: 1 addition & 0 deletions Calendar/local/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Stub so local is a module, used for third-party modules
39 changes: 39 additions & 0 deletions Calendar/plugin.py
Original file line number Diff line number Diff line change
@@ -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:
12 changes: 12 additions & 0 deletions Calendar/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
###
# Copyright (c) 2023, Matias Wilkman
# All rights reserved.
#
#
###

from supybot.setup import plugin_setup

plugin_setup(
'Calendar',
)
15 changes: 15 additions & 0 deletions Calendar/test.py
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit de8ac7a

Please sign in to comment.