Example #1
0
File: user.py Project: Fy-/domino
	def update_away(self, value):
		if not value:
			self.away = False
			send_numeric(305, [self.nick], ':You are no longer marked as being away', self)
		else:
			self.away = value
			send_numeric(306, [self.nick], ':You have been marked as being away', self)
Example #2
0
    def _part(user, chan_str):
        chan = Chan.create_or_get_chan(user, chan_str)
        if not chan:
            send_numeric(403, [user.nickname, chan_str],
                         ':No such nick/channel', user)
            return

        user.part(chan)
Example #3
0
File: chan.py Project: Fy-/domino
 def who(self, user):
     for my_user in self.users:
         send_numeric(352, [
             user.nick, self.name, my_user.hostname, my_user.server.name,
             my_user.nick,
             'H%s' %
             (self.modes.get_prefix(my_user)) if not user.away else 'G%s' %
             (self.modes.get_prefix(my_user))
         ], ':0 %s' % (my_user.realname), user)
     send_numeric(315, [user.nick, self.name], ':End of /WHO list.', user)
Example #4
0
File: user.py Project: Fy-/domino
def ISON(user, args):
	if len(args) == 0:
		return

	user_list = ''
	for user_str in args:
		_user = DominoData.users.get(user_str.lower())
		if _user:
			user_list += ' ' + _user.nick

	send_numeric(303, [user.nick], ':%s' % (user_list.strip()), user)
Example #5
0
File: user.py Project: Fy-/domino
def USERHOST(user, args):
	if len(args) == 0:
		return

	user_list = ''
	for user_str in args:
		_user = DominoData.users.get(user_str.lower())
		if _user:
			user_list += ' %s=%s' % (_user.nick, _user.userhost())

	send_numeric(302, [user.nick], ':%s' % (user_list.strip()), user)
Example #6
0
def NAMES(user, args):
    if len(args) != 1:
        send_numeric(461, [user.nick, 'NAMES'], ':Not enough parameters')
        return

    chan = DominoData.chans.get(args[0].lower())
    if not chan:
        send_numeric(401, [user.nickname, args[0]], ':No such nick/channel',
                     user)
        return

    chan.names(user)
Example #7
0
File: user.py Project: Fy-/domino
	def privmsg(self, target, data, cmd):
		if self.away:
			send_numeric(301, [self.nick, target.nick], ':%s' % (target.away), self)

		if '*' in DominoData.callback['on_privmsg']:
			for callback in DominoData.callback['on_privmsg']['*']:
				data = callback(self, data) or data

		if target.nick.lower() in DominoData.callback['on_privmsg']:
			for callback in DominoData.callback['on_privmsg'][target.nick.lower()]:
				data = callback(self, data) or data

		target.send(':%s %s %s :%s' % (self, cmd, target.nick, data))
Example #8
0
def WHO(user, args):
    # WHO #domino %ctnf,152
    if len(args) not in [1, 2]:
        send_numeric(461, [user.nick, 'WHO'], ':Not enough parameters', user)
        return

    if '#' in args[0]:
        chan = DominoData.chans.get(args[0].lower())
        if not chan:
            send_numeric(401, [user.nickname, args[0]],
                         ':No such nick/channel', user)
            return

        chan.who(user)
Example #9
0
File: serv.py Project: Fy-/domino
def LIST(user, args):
    send_numeric(321, [user.nick], 'Channel :Users  Name', user)
    if len(args) in [1, 0]:
        for chan in sorted(DominoData.chans.values(),
                           key=operator.attrgetter('count')):
            send_numeric(322, [user.nick, chan.name, chan.count],
                         ':[%s] %s' % (str(chan.modes).strip(" "), chan.topic),
                         user)

    if len(args) == 2:
        all_args = args.split(',')
        _max = 100000000
        _min = -1

        for _arg in _all_args:
            if _arg[0] == '>':
                _max = _arg.split('>')[0]

            elif _arg[0] == '<':
                _max = _arg.split('<')[0]

        i = 0
        for chan in sorted(DominoData.chans.values(),
                           key=operator.attrgetter('count')):
            if chan.count >= _max and chan.count <= _min:
                send_numeric(322, [user.nick, chan.name, chan.count],
                             ':[%s] %s' % (chan.modes, chan.topic), user)
                i = i + 1
                if i == 59:
                    break

    send_numeric(323, [user.nick], ':End of /LIST', user)
Example #10
0
File: chan.py Project: Fy-/domino
    def privmsg(self, user, data, cmd):
        if self.can_talk(user):

            if self.id in DominoData.callback['on_privmsg_chan']:
                for callback in DominoData.callback['on_privmsg_chan'][
                        self.id]:
                    data = callback(user, self, data) or data

            if '*' in DominoData.callback['on_privmsg_chan']:
                for callback in DominoData.callback['on_privmsg_chan']['*']:
                    data = callback(user, self, data) or data

            self.send(':%s %s %s :%s' % (user, cmd, self.name, data), me=user)

        else:
            send_numeric(404, [user.nick, self.name],
                         ':Cannot send to channel', user)
Example #11
0
File: mode.py Project: Fy-/domino
    def add(self, user, args):
        modes = list(args[1])
        action = modes[0]
        modes = modes[1:]
        for mode in modes:
            if mode in ['m', 'r', 's', 't']:
                if self.can(user, 'o') and len(args) == 3:
                    self.data[mode] = True if action == '+' else False
                    self.chan.send(':%s MODE %s%s' %
                                   (user, self.chan.name, action, mode))
                else:
                    send_numeric(461, [user.nick, self.chan.name],
                                 ': You\'re not a channel operator', user)
            elif mode in ['l']:
                if self.can(user, 'o'):
                    if len(args) == 4 and action == '+':
                        self.data[mode] = int(args[3])
                        self.chan.send(':%s MODE %s%s %s' %
                                       (user, self.chan.name, action, mode,
                                        self.data[mode]))
                    elif len(args) == 3 and action == '-':
                        self.data[mode] = False
                        self.chan.send(':%s MODE %s%s' %
                                       (user, self.chan.name, action, mode))
                else:
                    send_numeric(461, [user.nick, self.chan.name],
                                 ': You\'re not a channel operator', user)
            elif mode in ['q', 'a', 'o', 'v', 'h']:
                if len(args) == 3:
                    target = DominoData.users.get(args[2].lower())
                    if not target:
                        send_numeric(403, [user.nick, self.chan.name],
                                     ':No such nick/channel', user)
                    else:
                        if self.can(user, mode):
                            changed = False
                            if action == '+':
                                if target not in self.data[mode]:
                                    self.data[mode].add(target)
                                    changed = True
                            else:
                                if target in self.data[mode]:
                                    self.data[mode].discard(target)
                                    changed = True

                            if changed:
                                self.chan.send(':%s MODE %s %s%s %s' %
                                               (user, self.chan.name, action,
                                                mode, target.nick))
                else:
                    send_numeric(461, [user.nick, 'MODE'],
                                 ':Not enough parameters', user)
Example #12
0
File: chan.py Project: Fy-/domino
    def join(self, user):
        user.relatives |= self.users
        self.users.add(user)

        for my_user in self.users:
            my_user.relatives.add(user)

        self.send(':%s JOIN %s' % (user, self.name))

        send_numeric(329, [user.nick, self, self.created], '', user)
        if self.topic:
            send_numeric(332, [user.nick, self], ':%s' % (self.topic), user)
        else:
            send_numeric(331, [user.nick, self], ':No topic is set', user)

        self.modes.send(user)
        self.names(user)

        if len(self.users) == 1:
            if self.id in DominoData.callback['on_create_chan']:
                for callback in DominoData.callback['on_create_chan'][self.id]:
                    callback(user, self)

        if self.id in DominoData.callback['on_join_chan']:
            for callback in DominoData.callback['on_join_chan'][self.id]:
                callback(user, self)
Example #13
0
File: oper.py Project: Fy-/domino
def KILL(user, args):
    print('KILL', len(args))

    if not user.is_oper:
        send_numeric(481, [user.nick],
                     ':Permission Denied - You\'re not an IRC operator', user)
        return

    if len(args) not in [1, 2]:
        return

    target = DominoData.users.get(args[0].lower())

    if not target:
        send_numeric(401, [user.nick, args[0]], ':No such nick/channel', user)
        return

    reason = '...'
    if len(args) == 2:
        reason = args[1]

    target.kill(user, '☠ /killed by %s (%s) ☠' % (user.nick, reason))
Example #14
0
def TOPIC(user, args):
    if len(args) == 2 and '#' in args[0]:
        chan = DominoData.chans.get(args[0].lower())
        if not chan:
            send_numeric(401, [user.nickname, args[0]],
                         ':No such nick/channel', user)
            return

        chan.update_topic(user, args[1])
    elif len(args) == 1 and '#' in args[0]:
        chan = DominoData.chans.get(args[0].lower())
        if not chan:
            send_numeric(401, [user.nickname, args[0]],
                         ':No such nick/channel', user)
            return

        if chan.topic:
            send_numeric(332, [user.nick, chan], ':%s' % (chan.topic), user)
        else:
            send_numeric(331, [user.nick, chan], ':No topic is set', user)
    else:
        send_numeric(461, [user.nick, 'TOPIC'], ':Not enough parameters', user)
Example #15
0
File: user.py Project: Fy-/domino
def MODE(user, args):
	if len(args) == 0:
		return

	if '#' in args[0]:
		chan = DominoData.chans.get(args[0].lower())
		if not chan:
			send_numeric(401, [user.nick, args[0]], ':No such nick/channel', user)
			return

		if len(args) == 2:
			chan.modes.send()
		elif len(args) == 3:
			chan.modes.add(user, args)
			
	else:
		user = DominoData.users.get(args[0].lower())
		if not user:
			send_numeric(401, [user.nick, args[0]], ':No such nick/channel', user)
			return

		if len(args) == 2:
			user.modes.send()
Example #16
0
def PART(user, args):
    def _part(user, chan_str):
        chan = Chan.create_or_get_chan(user, chan_str)
        if not chan:
            send_numeric(403, [user.nickname, chan_str],
                         ':No such nick/channel', user)
            return

        user.part(chan)

    if len(args) == 0:
        return

    if '#' not in args[0]:
        send_numeric(403, [user.nickname, args[0]], ':No such nick/channel',
                     user)
        return

    if ',' in args[0]:
        for chan_str in args[0].split(','):
            _part(user, chan_str)
    else:
        _part(user, args[0])
Example #17
0
def JOIN(user, args):
    if len(args) != 1:
        send_numeric(461, [user.nick, 'JOIN'], ':Not enough parameters')
        return

    def _join(user, chan_str):
        chan = Chan.create_or_get_chan(user, chan_str)
        if not chan:
            send_numeric(403, [user.nickname, chan_str],
                         ':No such nick/channel', user)
            return

        user.join(chan)

    if '#' not in args[0]:
        send_numeric(403, [user.nickname, args[0]], ':No such nick/channel',
                     user)
        return

    if ',' in args[0]:
        for chan_str in args[0].split(','):
            _join(user, chan_str)
    else:
        _join(user, args[0])
Example #18
0
File: user.py Project: Fy-/domino
def PRIVMSG(user, args, command='PRIVMSG'):
	if len(args) == 1:
		send_numeric(412, [user.nick], ':No text to send', user)
		return
	if len(args) == 0:
		send_numeric(411, [user.nick], ':No recipient given', user)
		return

	if '#'in args[0]:
		chan = DominoData.chans.get(args[0].lower())

		if not chan:
			send_numeric(401, [user.nick, args[0]], ':No such nick/channel', user)
			return

		chan.privmsg(user, args[1], command)
	else:
		target = DominoData.users.get(args[0].lower())
		if not target:
			send_numeric(401, [user.nick, args[0]], ':No such nick/channel', user)
			return
		
		user.privmsg(target, args[1], command)
Example #19
0
File: user.py Project: Fy-/domino
def NICK(user, args):
	if len(args) != 1:
		send_numeric(461, [user.nick, 'NICK'], ':Not enough parameters')
		user.send(':%s PING %s :%s' % (user.server.name, user.server.name, ''))
		return

	if DominoData.users.get(args[0].lower()) != None and DominoData.users.get(args[0].lower()) != user:
		send_numeric(433, ['*', args[0]], ':Nickname is already in use.', user)
		user.send(':%s PING %s :%s' % (user.server.name, user.server.name, ''))
		return

	if not DominoData.re_nick.match(args[0]):
		send_numeric(432, ['*', args[0]], ':Erroneous nickname.', user)
		user.send(':%s PING %s :%s' % (user.server.name, user.server.name, ''))
		return

	user.update_nick(args[0])
Example #20
0
File: oper.py Project: Fy-/domino
def OPER(user, args):
    if user.server.config.get('opers'):
        if user.server.config['opers'].get(args[0]):
            if len(args) == 2:
                if check_password_hash(
                        user.server.config['opers'].get(args[0]), args[1]):
                    user.modes.data['O'] = True
                    user.modes.data['W'] = True
                    user.modes.send()

                    send_numeric(381, [user.nick],
                                 ':❤ You are now an IRC Operator ❤', user)
                    send_numeric(
                        381, [user.nick],
                        ':With great power comes great responsibility...',
                        user)

                    return

    send_numeric(464, [user.nick], ':Nice try! ❤', user)
Example #21
0
File: user.py Project: Fy-/domino
def WHOIS(user, args):
	if len(args) not in [1,2]:
		send_numeric(461, [user.nick, 'WHOIS'], ':Not enough parameters', user)
		return

	target = DominoData.users.get(args[0].lower())

	if not target:
		send_numeric(401, [user.nick, args[0]], ':No such nick/channel', user)
		return

	send_numeric(
		311,
		[user.nick, target.nick, target.username, target.hostname, '*'],
		':%s' % (target.realname),
		user
	)
	send_numeric(379, [user.nick, target.nick], ':is using modes %s' % (target.modes), user)

	if len(user.channels) > 0:
		send_numeric(
			319,
			[user.nick, target.nick],
			':%s' % ' '.join([chan.modes.get_prefix(target) + chan.name for chan in target.channels]),
			user
		)

	if target.away:
		send_numeric(301, [user.nick, target.nick], ':%s' % (target.away), user)

	if target.modes.has('B'):
		send_numeric(335, [user.nick, target.nick], ':is a Bot on %s' % (user.server.name), user)
	if target.is_oper:
		send_numeric(313, [user.nick, target.nick], ':✩✩✩ IRC operator, show some respect! ✩✩✩', user)

	if target.is_registered:
		send_numeric(307, [user.nick, target.nick], ':is identified for this nick', user)
		send_numeric(330, [user.nick, target.nick, target.nick], ':is logged in as', user)

	send_numeric(317, [user.nick, target.nick, (int(time.time()) - target.idle), target.created], ':seconds idle, signon time', user)
	send_numeric(312, [user.nick, target.nick, target.server.name], ':%s' % (user.server.name), user)
	send_numeric(318, [user.nick, target.nick], ':End of /WHOIS list.', user)
Example #22
0
File: user.py Project: Fy-/domino
def USER(user, args):
	if len(args) != 4:
		user.die("What?")
		return

	if user.is_ready == True:
		send_numeric(462, [user.server.name], ':You may not re-register.', user)
		return

	user.realname = args[3]
	user.username = args[0]

	if user.nick and user.welcomed == False:
		#: Greetings!
		send_numeric(1, [user.nick], ':Welcome to %s %s' % (user.server.name, user.nick), user)
		send_numeric(2, [user.nick], ':Your host is "%s", running version %s' % (user.server.name, user.server.version), user)
		send_numeric(3, [user.nick], ':This server was created on %s' % (user.server.created), user)
		send_numeric(4, [user.nick], '%s %s %s %s' % (user.server.name, user.server.version, UserMode.concat(), ChanMode.concat()), user)
		options_txt = [
			'CMDS=USERIP,STARTTLS,KNOCK,DCCALLOW,MAP UHNAMES NAMESX SAFELIST HCN MAXCHANNELS=30 CHANLIMIT=#:30 MAXLIST=b:60,e:60,I:60 MAXNICKLEN=50 NICKLEN=50 CHANNELLEN=50 TOPICLEN=255 KICKLEN=255',
			'AWAYLEN=255 WALLCHOPS WATCH=128 WATCHOPTS=A SILENCE=15 MODES=12 CHANTYPES=# PREFIX=(ohv)@%+ CHANMODES='+ ChanMode.concat_modes() +' NETWORK=2Kay CHARSET=utf-8',
			'ELIST=MNUCT STATUSMSG=@%+ EXCEPTS INVEX'
		]
		for option_txt in options_txt:
			send_numeric(5, [user.nick], '%s %s :Are supported by this server' % (user.nick, option_txt), user)


		#: Host
		send_numeric(396, [user.nick], '%s :is now your displayed host' % user.hostname, user)

		#: Stats
		send_numeric(251, [user.nick], ':There is %s users on %s' % (len(DominoData.users), user.server.name), user)
		send_numeric(252, [user.nick], ':There is %s channels on %s' % (len(DominoData.chans), user.server.name), user)

		#: MOTD
		send_numeric(252, [user.nick], ':- %s, message of the day -' % (user.server.name), user)
		for l in user.server.motd:
			send_numeric(372, [user.nick], ':- %s' % l.strip('\n'), user)
		send_numeric(376, [user.nick], ':End of /MOTD command', user)


		if len(user.server.config['auto_join']) >= 1:
			for chan_str in user.server.config['auto_join']:
				chan = Chan.create_or_get_chan(user, chan_str)
				user.join(chan)
Example #23
0
File: chan.py Project: Fy-/domino
 def names(self, user):
     for data in split_string_512(self.user_list):
         send_numeric(
             353, [],
             '%s = %s :%s' % (user.nick, self.name, data.strip(' ')), user)
     send_numeric(366, [user.nick, self.name], ':End of /NAMES list.', user)
Example #24
0
File: serv.py Project: Fy-/domino
def USERS(user, args):
    send_numeric(265, [user.nick, len(DominoData.users)],
                 ':Current local users %s' % (len(DominoData.users)), user)
Example #25
0
File: mode.py Project: Fy-/domino
 def send(self, user):
     send_numeric(324, [user.nick, self.chan.name,
                        self.__str__()], '', user)