diff --git a/ircbotpoll.py b/ircbotpoll.py new file mode 100644 index 0000000..e544451 --- /dev/null +++ b/ircbotpoll.py @@ -0,0 +1,150 @@ +#!/usr/bin/env python3 + +################################################################ +# IRC Bot for creating polls # +# # +# Created by q3aql (q3aql@duck.com) # +# Licensed by GPL v2.0 # +# Last update: 27-08-2025 # +# # +# Requirements: # +# pip install irc # +################################################################ + +import sys +import time +import signal +import logging +from collections import defaultdict +from threading import Event, Thread + +import irc.client + +######## CONFIGURATION (Edit with your settings) +SERVER = "irc.example.net" +PORT = 6667 +USE_TLS = False +NICK = "poll-bot" +REALNAME = "IRC Poll Bot" +CHANNELS = ["#support", "#linux"] +######### + +polls = {} + +def on_connect(conn, event): + logging.info("Connected to %s:%s", SERVER, PORT) + for chan in CHANNELS: + conn.join(chan) + logging.info("Joining %s", chan) + +def on_join(conn, event): + nick = irc.client.NickMask(event.source).nick + channel = event.target + + if nick == NICK: + return + + logging.info("%s has joined %s", nick, channel) + +def on_pubmsg(conn, event): + channel = event.target + nick = irc.client.NickMask(event.source).nick + message = event.arguments[0] + + if message.startswith("!poll"): + create_poll(conn, channel, message) + elif message.startswith("!vote"): + cast_vote(conn, channel, nick, message) + elif message.startswith("!results"): + show_results(conn, channel) + elif message.startswith("!endpoll"): + end_poll(conn, channel) + +def create_poll(conn, channel, message): + parts = message.split(" ", 1) + if len(parts) < 2: + conn.privmsg(channel, "Usage: !poll ") + return + + question = parts[1] + if channel in polls: + conn.privmsg(channel, "A poll is already active. Please end it before starting a new one.") + return + + polls[channel] = {"question": question, "votes": defaultdict(int)} + conn.privmsg(channel, f"Poll created: {question} - Use !vote