Example #1
0
    def ircbot(self):
        # Create database at first run
        if not os.path.exists('db/'+self.irc_host+'.sqlite'):
            db_process.start(self)
        # Connect to Stream Server
        threading.Thread(target=self.stream_server).start()

        try:
            while True:
                conn, cur = self.db_data()
                sql = """UPDATE users
                        SET state = 0;
                        DELETE FROM user_channel;
                """
                cur.executescript(sql)
                conn.commit()
                cur.close()
                if self.plugins_support:
                    # run plugins
                    fns = [openra_topic.start, openra_bugs.start, github_commits.start,
                        openra_game.start]
                    procs = [multiprocessing.Process(target=f, args=(self,)) for f in fns]
                    print(("[%s] Plugins support...\t\tOK") % (self.irc_host))
                    self.plugins('start', procs)

                if self.connect():
                    if ( self.connect_return == 'Excess Flood' ):
                        if self.plugins_support:
                            self.plugins('terminate', procs)
                            print("[%s] Terminated child processes" % self.irc_host)
                        print("[%s] Restarting the bot" % self.irc_host)
                        time.sleep(5)
                        self.irc_sock.close()
                        continue
                    elif ( self.connect_return == 'Manual Quit' ):
                        if self.plugins_support:
                            self.plugins('terminate', procs)
                            print("[%s] Terminated child processes" % self.irc_host)
                        print("[%s] Exit" % self.irc_host)
                        break
                self.close_threads = [1]
        except KeyboardInterrupt:
            self.close_threads = [1]
            raise KeyboardInterrupt
Example #2
0
import sqlite3
import random
import pywapi
import urllib.request
import imp
import inspect

import db_process
import notifications
import config
import spam_filter
from commands import *

###
if not os.path.exists('db/openra.sqlite'):
    db_process.start()
###

# Defining a class to run the server. One per connection. This class will do most of our work.
class IRC_Server:

    # The default constructor - declaring our global variables
    # channel should be rewritten to be a list, which then loops to connect, per channel.
    # This needs to support an alternate nick.
    def __init__(self, host, port, nick, channel , password =""):
        self.irc_host = host
        self.irc_port = port
        self.irc_nick = nick
        self.irc_channel = channel
        self.irc_sock = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
        self.is_connected = False