Commit Graph

101 Commits

Author SHA1 Message Date
Tony Breeds 287f8d5063 Set SO_REUSEADDR and SO_REUSEPORT to enable faster service restarts
In a fast restart of the service we don't have time for all the TCP
sessions to drain the sockets in TIME_WAIT.  So the service fails to
restart with a "bind address in use".   To avoid this we want to add
SO_REUSEADDR and SO_REUSEPORT.  To do so we have to disable
bind_and_activate so we can then set allow_reuse_address and
allow_reuse_address on the TCPServer before we bind.

For reference:
 * https://docs.python.org/3/library/socketserver.html#socketserver.BaseServer.allow_reuse_address
 * https://github.com/python/cpython/blob/3.11/Lib/socketserver.py#L445
 * https://github.com/python/cpython/blob/3.11/Lib/socketserver.py#L447

Change-Id: I2ecbedf43e9912d430197e4110e4d467a8b449a3
2023-10-04 17:23:05 +11:00
Tony Breeds d01468e188 Fix errors in iCal
There were several issues with generating the ptg.ics.

Errors causing python tracebacks:

1. teams = slots = {}
   This was a gotcha for me.  This essentially makes teams and slots
   aliases for the *same* empty dictionary.  Not as I thought creating
   creating 2 empty dictionaries.  Upon reflection it is obvious.

   This meant that I was treating a "slot code" [MonA1] as a track/team

2. datetime.timedelta()'s keyword is "minutes" not "mins"

Functional errors:

1. If a team/track sets a VC url, it goes into db["urls"].
   Look there first and if not there look for a URL from the slot/room
   location.

2. Use a reasonable isn't a team/track key in db["etherpads"].

Non-functional changes:

1. There were a couple of FIXMEs which were addressed.
   e["key"] = "value" is the same as e.add("key", "value")

2. An empty url (""), is fine to add into the location, just strange.

Change-Id: I458924bfc26c47f4e062cc16f48e2d72da361918
2023-10-04 10:41:00 +11:00
Tony Breeds f3060c0806 [iCal] Add an iCal file route.
Add a handler that converts the existing slot data into an ICS file.
This .ics file can be global ".../ptg.ics" or per track ".../ironic.ics"

Right now each block deafults to 60 minutes if there isn't a 'duration'
field in the slot entry.

Change-Id: I7a67ba777c004e57206976aca377fe3f41956db0
2023-09-25 11:58:42 +10:00
Clark Boylan 513944afea Update ptgbot to python3.11 and Bookworm
We update python testing from python3.8 to python3.11 to match the
deployment setup in the Docker image. We then update the docker image
from python3.9 + bullseye to python3.11 + bookworm. This is future
proofing, but also OpenDev would like to clean up old docker container
image builds for bullseye and older python.

Change-Id: Ifbb7dcf2bf5f0b7ea4f53e26dd4bf4911c9b8d37
2023-09-19 11:13:56 -07:00
Kendall Nelson 8ddd44bb1c Update Bot to Show Room Descriptions
Also adds examples of text for the description field
to base.json

Change-Id: Iac2201b9220db2c9b4c07a72cae1437b3f97de3a
2022-05-12 06:44:05 -05:00
Ian Wienand 0e2f3d0a9d ptgbot-web: add simple service to serve static pages
This serves the static pages from the container directly

Change-Id: I86f3f5002f88005760e00c5714b0891c1892a6f2
2021-10-05 14:38:56 +11:00
Thierry Carrez ab85e55d74 Adapt PTGBot to OFTC
PTGBot was relying on a number of Freenode things and requires a
few changes to run on OFTC:

- Manually identify to NickServ instead of using SASL
- No longer use identify-msg capability
- Messages received are no longer prefixed by '+'

Change-Id: Ib014f58475c1eee89d34e718ee5988800602586b
2021-05-31 15:38:52 +02:00
Thierry Carrez 6445b85ccd Add missing clear clean alias
Recent change to introduce a "clear" alias for the "clean" commands
missed one case (~clear TRACK).

Change-Id: I60334ce80fee07edca335c1a75a295d90d6c39c5
2021-04-22 14:21:01 +02:00
Tim Burke ce24fed50c Add "clear" as an alias for "clean"
Change-Id: I5a5e9107850c008047dd875fe3901f1dd0ec2ea2
2021-04-21 07:56:46 -07:00
Thierry Carrez 5a791cde41 Fix airbag deployment on empty messages
PTGbot airbag deploys on empty messages (messages containing only
spaces, or /me actions). Fix this crash to avoid airbag deployment.

Change-Id: I4def945894419536fd3d340e3850007210adf17f
2021-04-16 11:23:32 +02:00
Thierry Carrez b728b153e4 Fix ~add ~del ~clean commands
The first parameter would be ignored when running ~add, ~del or
~clean commands. Fix the issue and add a test to make sure we
do not regress again.

Change-Id: If2c239e8d04ca2ea86283861617c89d77d3917ee
2021-04-16 11:09:24 +02:00
Thierry Carrez 7beb7de516 Refactor processing of track and admin commands
Separate the processing of track commands and admin commands
into separate files, and normalize handling of messages.

Adjust test cases so that they match the new normalized messages.

Change-Id: I26e3683bbf3b7daab68407cd9928ee3d7f5c50dc
2020-12-08 14:35:48 +01:00
Thierry Carrez 2f8c18d9c1 Refactor processing of user commands
User commands in PTGbot can be called from privmsg or pubmsg.
Create a usercommands.py file to separate their processing.

This introduces a new '+' prefix for user commands, while preserving
the old '#' calls (which should really only be used for track
commands) for people that got used to them.

Change-Id: Ifab12fa27c6147ba9e9ff51f2b7f9e30a8ed0076
2020-12-08 14:35:48 +01:00
Thierry Carrez f368b40e98 Add tests for user commands
Add tests for in/out/seen and subscribe/notify/unsubscribe features.

Change-Id: I15313f93e728a692820ac79644d70928d87b3f2a
2020-12-08 14:35:37 +01:00
Thierry Carrez 5f371d18d4 Add tests for PTGbot
Add tests for most commands in PTGbot, checking that they result in
the desired outcome.

With this patch all track commands are tested, as well as most admin
commands.

Change-Id: I0a9907da6946db224a9efd2c740f275dfad0f00e
2020-11-27 09:43:46 +01:00
Thierry Carrez 21fbc34f3e Add memory-only database mode
Add a DB creation mode that will not persist changes to disk,
to be used in unit testing.

Change-Id: I3eeac5ddc1a360c1a4ed9dc892720ae92da1de87
2020-11-25 16:03:10 +01:00
Thierry Carrez 6bf2598db6 Create functions for is_voiced and is_oper checks
In order to be able to easily mock voice and oper checks, create
specific functions that implement those checks.

Change-Id: I6250c0d181085ff39d6ff0dae95c700dbeb931a3
2020-11-25 16:01:28 +01:00
Thierry Carrez df17b77f7e Log exception when bot airbag is activated
To facilitate investigating airbag-prevented PTGbot crashes,
log the exception stacktrace.

Change-Id: I6600abc1f07f16b739c62aeb632bd5bfd9a5e3e9
2020-11-25 15:59:56 +01:00
Zuul 39985b866d Merge "PTGbot airbag to prevent unexpected crashes" 2020-11-19 16:09:57 +00:00
Thierry Carrez a0d3fbab41 Add new MOTD handling commands
Revamp the ~motd command so that it supports the following subcommands
on the newly-introduced array of MOTD messages:

~motd add... (equivalent to old ~motd): adds a message
~motd clean (equivalent to old ~cleanmotd
~motd del n (to suppress message #n)
~motd reorder x y z (to reorder/remove messages)

Change-Id: I2f98c724c716ca4fd2e8fef34d4ca5af457b39e8
2020-11-13 18:14:52 +01:00
Thierry Carrez 9e052b1625 Turn MOTD into a list of messages
The message of the day used to be a single message with an importance
level. It's actually useful to be able to have several distinct
messages and add/remove them separately.

In preparation for that change, turn the motd entry in the json DB into
an array of messages. Gracefully migrate previous format DB into the
new one. Commands stay unchanged for now and just manipulate the first
entry.

Change-Id: Id98281dba0c6b3cffe1a359d6e0c250b99084bb1
2020-11-13 17:39:19 +01:00
Thierry Carrez 2aa77f38a4 PTGbot airbag to prevent unexpected crashes
Catch all previously-uncaught exceptions from on_pubmsg() and
on_privmsg() calls, to prevent the bot from crashing when people
start getting creative in their commands.

This should of course never happen, but if it does, better continue
running than crash.

Change-Id: Ic5eeec23652170061cbd2ce3606a3aee22463529
2020-11-13 13:15:03 +01:00
Thierry Carrez d172bd0cef Fix potential crash in etherpad command code
The code handling the "etherpad" command had the same issue as the
code handling the "url" command: if "auto" was passed to reset an
etherpad to default BUT no etherpad was set, the bot would crash.
This fixes it by doing nothing in that corner case.

Change-Id: I7a63c0b5ce95cf795964e637313a7b19e238964d
2020-10-30 14:41:03 +01:00
Thierry Carrez 902bce5867 Fix bot crash when 'none' URL provided
If a "none" URL is passed for a track but that track did not
have a customized URL in the first place, the bot would crash.
This fixes it by not doing anything in that case.

Change-Id: I9ab45ad7d07700efe5af208eb4c5b1285fd9deeb
2020-10-30 14:35:25 +01:00
Thierry Carrez 673d5375cd Make clickable badges more button-like
Make it clearer that certain badges are meant to be clicked on.
Also replace the darkblue badge color that was too close to the
hover color.

Change-Id: I84617dbd442cfd557155400a65bd87679fe2825a
2020-09-14 13:50:02 +02:00
Thierry Carrez 1db00eafb8 Do not crash on privmsg with no content
There is a corner case (/dcc chat) where a privmsg can have no content.
Ignore such corner cases instead of crashing.

Change-Id: Ia07c76c4a2342bb4e7bc9c37a4944d4b9f18efd8
2020-06-02 15:38:07 +02:00
Thierry Carrez 5538127768 Support for room and track URLs
Allow to associate a URL to a room, for example a link to a video
conference room. Tracks assigned to this room will automatically inherit
the link. The link for a given track can be overridden using the "url"
command.

This allows organizers to provide video links for each room, while still
enabling teams to link to whatever they end up really using.

Change-Id: I633eb83c579e4093ae769bcd053e4d2ec2fe4bc3
2020-05-05 12:17:51 +02:00
Thierry Carrez c360e15043 Generate etherpad links automatically
With this change, the ptgbot will generate links for each track
etherpad, display them on a specific page (etherpads.html) and
allow track moderators to override the autogenerated link using
the #track etherpad command.

It requires the database to contain an 'eventid' key which serves
as a unique etherpads prefix.

Change-Id: Iaa524530e9f2506369f180588a2b6f98f4cad3d1
2019-08-23 17:21:04 +02:00
Thierry Carrez 7e1f5c3715 Display room capabilities
It is sometimes useful to mark certain rooms as having specific
capabilities like videoprojection. This change adds the possibility
to assign a glyphicon (cap_icon) and a mouseover description
(cap_desc) for the rooms in the schedule dictionary.

Change-Id: I343c28acc3ad6015d3382d526511f153bf38a0e6
2019-08-05 16:51:10 +02:00
Thierry Carrez 18dbbc69f4 Clean up stale data presence on a #newday command
Data presence was not reset on a new day cleanup, while it
is almost certainly stale at this point. Hopefully.

Change-Id: Ifc4cdedf6c365f92e5ff001d1485c8fee21b396f
2019-07-12 16:56:58 +02:00
Thierry Carrez 170c75cd16 Reset to OrderedDict on new day cleanup
While originally created as an OrderedDict, some data tables
were reset to a basic dictionary on a #newday command.

Change-Id: I62539a8c7130eac5eb666af019b7c94078666656
2019-07-12 16:52:09 +02:00
Adam Spiers 0145545e78 Fix crash after #unsubscribe
The #unsubscribe command was setting the person's subscription to None
which obviously can't be compiled to a regex.  This caused a crash on
the first now/next update after someone did #unsubscribe.  Fix this
simply by skipping any subscription where the regex is set to None.

Change-Id: I11d42bcb1a0e3bc2e4105d6c2afa39f3a37af278
2019-05-03 09:42:29 -06:00
Adam Spiers b14ec32f05 Check that subscription regexen compile before accepting them
Previously we blindly accepted any string as a regex, but then
it could fail to compile at search-time when a track topic got
updated, which would cause the bot to crash.

So do a precautionary compile of the regex in order to ensure
we only accept valid regexen.

Change-Id: Id347b88adfc7150ff26550cf9170071e7ac33227
2019-05-02 11:21:14 -06:00
Zuul 4fbaf41725 Merge "Add subscribe command for automatic notifications of topics" 2019-04-30 21:49:16 +00:00
Zuul 0a4cb3d526 Merge "update git.openstack.org to opendev" 2019-04-30 21:32:10 +00:00
Zuul 932cb5df03 Merge "Recognise when user forgets # prefix for a track check-in" 2019-04-30 21:31:43 +00:00
Adam Spiers e8f88b2ee1 Add subscribe command for automatic notifications of topics
Add a new 'subscribe' command which allows people to subscribe for
automatic notifications via direct message of topics which match the
subscription regex they provide.  With no regex argument it shows the
user's current subscription (if any).  Also add a new 'unsubscribe'
command for clearing the regex.

Example use cases:

1. I know that nova is planning to discuss $TOPIC some time tomorrow
   but they don't know exactly when, and I want to spend most of the
   day in another room whilst ensuring I don't miss that particular
   discussion on $TOPIC => "/msg ptgbot subscribe $TOPIC" will give me
   notifications when the PTL types "#nova next $TOPIC" and "#nova now
   $TOPIC".

2. I'm interested in *all* discussion on Python 3.  I don't know which
   projects are planning to discuss it, let alone when, but that
   doesn't matter, because I can type "/msg ptgbot subscribe python ?3"
   and get notified of all Python 3 discussions.

As with the presence tracking commands, these commands can be used in
public channels by preceding them with a '#' character.

Change-Id: I3f51acc318ecf31d435768640cef6c46d8ca136c
2019-04-30 13:06:58 -06:00
Adam Spiers 36a7857d45 Remove joke when asking when self was last seen
As discussed in I0d88a540ad7a333841c208dd7f2a7247897eb238, there are
good reasons for someone asking where they themself were last seen,
e.g. to verify that their current status is correct, or just for
testing the bot.  So remove the joke.  Perhaps we can find
another (funnier) Easter egg to add instead.

Change-Id: Ib27c72a20e71f0835e103e306b145d41a089131c
2019-04-28 22:03:07 -06:00
Adam Spiers e730d58f15 Recognise when user forgets # prefix for a track check-in
Since the in / #in command allows free-form check-ins when the
location is not prefixed with '#', this would allow people to
check into locations like 'nova' which would not be recognised
as an official track location.  As a result their attendance
would not show up in the tooltips on the schedule web page.

So automatically detect when the user is checking into a track
but forgot to use the '#' prefix, and add it automatically for
them.  This DWIM behaviour should avoid some confusion.

Also when matching / matched against known tracks, the lower-cased
version will be used.  This assumes that all registered tracks are
lower-case.

Change-Id: Ic88ba926ba9e3187da6046972344bc2b31e3c4f1
2019-04-28 12:04:50 -06:00
liuwei 28f90fbf21 update git.openstack.org to opendev
Change-Id: I4120656bd160ccfafee1998b56676465a7b023f3
2019-04-28 08:40:20 +00:00
Adam Spiers 946d69b140 Add presence tracking commands
Add in/out/seen commands to let people voluntarily check in and out of
tracks and other arbitrary locations, to make it easy for others to
find them.  Of course this is entirely optional.

It's designed to cope gracefully with people forgetting to check out
of locations they previously checked into.

Change-Id: I0d88a540ad7a333841c208dd7f2a7247897eb238
2019-04-26 19:07:07 +01:00
Thierry Carrez ed359e957a Order JSON config import
We should also retain order when importing JSON from a URL.

Change-Id: I27ffb63de17606893779c7c4c002aee15d7b56e0
2019-04-17 13:45:37 +02:00
Thierry Carrez cfc93cb8d8 Preserve JSON dictionary order
Load JSON db into ordered dictionaries so that the order of
days is preserved.

Change-Id: Icef5daf95271b0e8f1da61ee20eee1d4d3cd2c79
2019-04-15 16:29:57 +02:00
Thierry Carrez cb0e38cd12 Generate PTGbot index page dynamically
Current system (where the index page is specified in the
puppet-ptgbot module) requires that (some) links on the page
are updated in puppet-ptgbot at the start of every event.

That page should be dynamically generated from JSON data.
That way the list of links can be provided in the JSON database
and dynamically imported and updated using the ~fetchdb command.

Change-Id: I7d82b38cba495e5837ba54fbe7a9b7e9c8e14259
2018-12-21 15:35:30 +01:00
Thierry Carrez 6f9be1606a Allow unscheduled tracks to use now/next
PTGbot used to reject now/next (and location) commands for
tracks that do not have a room scheduled on the same day.

However, it is sometimes useful for teams to indicate such
a message (double-booked rooms, team photo time, etc), so
PTGbot will now issue a warning rather than reject command.

Change-Id: Ib04fbf860b22a3b2e99b106f4f83ae702dd215d8
2018-11-26 15:04:07 +01:00
Thierry Carrez af5bab2f3e Give better hints in case of command errors
The most common error interacting with the bot is omitting
the "now" command. This change makes ptgbot issue a helpful
suggestion, and clarifies a couple more error messages.

It also provides usage help in case anyone asks for #help.

Change-Id: Ifbee88ab15dbf0ed8c9f858072852381b9da168f
2018-11-26 14:51:56 +01:00
Thierry Carrez 3b59f982f8 Add emergency messages (~motd and ~cleanmotd)
Add admin command to add (and clean) a message of the day (motd)
to the rendered page. Can be used for emergency messages (using
level 'danger') or more general information.

Change-Id: Ie84d1a826c2f84a7ccdafd08176eef9aa2c5a3f1
2018-11-26 14:34:31 +01:00
Thierry Carrez 57d849493b Make 'unbook' available for all
The ability to unbook rooms should be accessible to all users.

Change-Id: If747141f9cfc1cd74b542071a798cf94ff1db309
2018-11-26 14:05:08 +01:00
Thierry Carrez 894c8672e8 Rename ~reload to ~emptydb
Reload now effectively empties the database completely,
so rename the function for clarity.

Change-Id: I5c30a89213e462dd3777052d6a6c2714039bbb76
2018-11-26 13:40:19 +01:00
Thierry Carrez 42451c744b Load base schedule dynamically
The base schedule was specified in the bot configuration file,
which made it a bit painful to do last-minute configuration.

The bot shall load a basic minimal database and support being
configured online instead, using commands and json imports.

This change removes the schedule loading from configuration,
and replaces it with a function to update the database using
a provided JSON URL (the ~fetchdb admin command).

Change-Id: I4e7a79baf88cce8d827eb66b1b0c26584c62c8d7
2018-11-26 13:38:26 +01:00