Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Change Topic on space status change #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
# MIT
# 2019 Alexander Couzens <[email protected]>

import asyncio
import logging
import logging.config
import yaml
import re
import sys
import asyncio
import async_timeout
from configparser import ConfigParser
from datetime import datetime
import pydle

import aioredis
import aiohttp

from amqtt.client import MQTTClient, ClientException
import aioredis
import async_timeout
import pydle
import yaml
from amqtt.client import ClientException, MQTTClient
from amqtt.mqtt.constants import QOS_2

from configparser import ConfigParser

LOG = logging.getLogger("v4runa")

MQTT_CONFIG = {
Expand Down Expand Up @@ -224,6 +223,14 @@ async def say_state(self, state, target=None):
await self.irc.notice(channel, "The space is now %s." % human[state])
if state == _CLOSED:
await self.irc.notice(channel, ".purge")
await self.update_topic(channel, human[state])

async def update_topic(self, channel, state_human):
old_topic = channel['topic']
if not old_topic or ': ' not in old_topic:
return
new_topic = re.sub(r"(space[^:]*:) \w+", "\\1 " + state_human, old_topic, flags=re.IGNORECASE)
await self.irc.set_topic(channel, new_topic)

async def check_room_status(self):
"""
Expand Down