コード例 #1
0
ファイル: Core.py プロジェクト: DomeniqueHunter/Chatbot
 async def _join(self, channel, true_name = None):
     data = {'channel': channel}
     if channel not in self.channels:
         if true_name:
             self.channels[channel] = Channel(true_name, channel)
         else:    
             self.channels[channel] = Channel(channel, channel)
             
     await self._message(opcode.JOIN_CHANNEL, data)
コード例 #2
0
def handle_modechg(event, message):
    target_is_channel = False
    source = message.source
    target = modelist = None
    params = []
    if (event.eventName.split("/")[-1] == "UMODE2"):
        target = source
        modelist = message.parameters[0]
    else:
        target = message.parameters[0]
        modelist = message.parameters[1]
        if (target[0] in ("#", "&", "+")):
            target_is_channel = True
            params = message.parameters[2:]

    if (target_is_channel):
        if (not Server.findByName(source) is None and params[-1].isdigit()):
            timestamp = long(params[-1])
        else:
            timestamp = time.time()

        channel = Channel.findByName(target)
        if (channel is None): return
        if (channel.timestamp == timestamp):
            channel.setModes(modelist, params, True)
        elif (channel.timestamp > timestamp):
            channel.clearModes()
            channel.setModes(modelist, params)
    else:
        client = Client.findByNick(target)
        if (client is None): return
        client.changeModes(modelist)
        log.debug("%s changed modes of %s to %s", source, client.nick,
                  client.usermodes)
コード例 #3
0
ファイル: ffs_core.py プロジェクト: BasementCat/ffservices
def handle_modechg(event, message):
	target_is_channel=False
	source=message.source
	target=modelist=None
	params=[]
	if(event.eventName.split("/")[-1]=="UMODE2"):
		target=source
		modelist=message.parameters[0]
	else:
		target=message.parameters[0]
		modelist=message.parameters[1]
		if(target[0] in ("#", "&", "+")):
			target_is_channel=True
			params=message.parameters[2:]
	
	if(target_is_channel):
		if(not Server.findByName(source) is None and params[-1].isdigit()):
			timestamp=long(params[-1])
		else:
			timestamp=time.time()
		
		channel=Channel.findByName(target)
		if(channel is None): return
		if(channel.timestamp==timestamp):
			channel.setModes(modelist, params, True)
		elif(channel.timestamp>timestamp):
			channel.clearModes()
			channel.setModes(modelist, params)
	else:
		client=Client.findByNick(target)
		if(client is None): return
		client.changeModes(modelist)
		log.debug("%s changed modes of %s to %s", source, client.nick, client.usermodes)
コード例 #4
0
 async def _hook_get_users_in_channel(self, user=None, channel=None):
     code = Channel.find_channel_by_name(self.channels, channel)
     if ((code in self.channels) and (self.is_priviliged(user))):
         message = 'Info for Channel [b]{}[/b] ({})\n'.format(
             self.channels[code].name,
             self.channels[code].characters.size())
         for char in self.channels[code].characters.get():
             message += "[user]{}[/user]\n".format(char)
         await self.send_private_message(message, user)
コード例 #5
0
    async def _get_full_client_list(self, user, channel=None):
        if self.client.is_owner(user) and channel:
            channel = Channel.find_channel_by_name(self.client.channels,
                                                   channel)
            message = "\nAll Clients\n"
            for char in self.all_clients[channel]:
                message += "[user]{}[/user]\n".format(char)

            await self.client.send_private_message(message, user)
コード例 #6
0
def handle_join(event, message):
    client = Client.findByNick(message.source)
    if (client is None): return
    chan = Channel.findByName(message.parameters[0])
    if (chan is None):
        chan = Channel(message.parameters[0], time.time())
        Channel.addChannel(chan)
    chan.addClient(client)
    log.debug("%s has joined %s", client.nick, chan.name)
コード例 #7
0
ファイル: Ranch.py プロジェクト: DomeniqueHunter/Chatbot
 def is_milking_channel(self, channel):
     allowed_channels = self.client.config.plugins['ranch']['channels']
     #print(f"channel: {channel}")
     for allowed_channel in allowed_channels:
         try:
             probe = Channel.find_channel_by_name(self.client.channels, allowed_channel)
             
             if probe == channel:
                 return True
         except Exception as e:
             print (f"Exception {e}")
     
     return channel in allowed_channels
コード例 #8
0
def handle_join(event, message):
	client=Client.findByNick(message.source)
	if(client is None): return
	chan=Channel.findByName(message.parameters[0])
	if(chan is None):
		chan=Channel(message.parameters[0], time.time())
		Channel.addChannel(chan)
	chan.addClient(client)
	log.debug("%s has joined %s", client.nick, chan.name)
コード例 #9
0
def handle_leave(event, message):
	source=Client.findByNick(message.source)
	if(source is None): source=Server.findByName(message.source)
	if(source is None): return
	targetchan=Channel.findByName(message.parameters[0])
	if(targetchan is None): return
	if(message.command=="PART"):
		targetuser=source
		reason=message.parameters[-1] if len(message.parameters)>1 else "[none]"
	elif(message.command=="KICK"):
		targetuser=Client.findByNick(message.parameters[1])
		if(targetuser is None): return
		reason=message.parameters[-1]
	log.debug("%s has left %s: %s: %s",
		targetuser.nick,
		targetchan.name,
		"kicked by "+(source.nick if source.__class__.__name__=="Client" else source.name) if message.command=="KICK" else "PART",
		reason
		)
	targetchan.removeClient(targetuser)
コード例 #10
0
def handle_leave(event, message):
    source = Client.findByNick(message.source)
    if (source is None): source = Server.findByName(message.source)
    if (source is None): return
    targetchan = Channel.findByName(message.parameters[0])
    if (targetchan is None): return
    if (message.command == "PART"):
        targetuser = source
        reason = message.parameters[-1] if len(
            message.parameters) > 1 else "[none]"
    elif (message.command == "KICK"):
        targetuser = Client.findByNick(message.parameters[1])
        if (targetuser is None): return
        reason = message.parameters[-1]
    log.debug(
        "%s has left %s: %s: %s", targetuser.nick, targetchan.name,
        "kicked by " +
        (source.nick if source.__class__.__name__ == "Client" else source.name)
        if message.command == "KICK" else "PART", reason)
    targetchan.removeClient(targetuser)
コード例 #11
0
ファイル: Core.py プロジェクト: DomeniqueHunter/Chatbot
 async def _invite_user_to_channel(self, user, channel_name):
     channel_code = Channel.find_channel_by_name(self.channels, channel_name)
     if channel_code:
         data_invite = {'channel': channel_code, 'character': user}        
         await self._message(opcode.INVITE, data_invite)        
コード例 #12
0
ファイル: Core.py プロジェクト: DomeniqueHunter/Chatbot
 async def _load_channels_from_file(self, file):    
     print ('FILE:', self.data_path+"/"+file)
     channels = Channel.load_file(self.data_path+"/"+file)         
     for i in channels:
         print (channels[i].name)
         await self._join(channels[i].code, channels[i].name)
コード例 #13
0
ファイル: Core.py プロジェクト: DomeniqueHunter/Chatbot
 def _save_channels_to_file(self, file):
     Channel.save_file(self.channels, self.data_path+"/"+file)
コード例 #14
0
def handle_topicchg(event, message):
	chan_name, who, ts, topic=message.parameters
	chan=Channel.findByName(chan_name)
	if(chan is None): return
	chan.setTopic(topic, who, ts)
コード例 #15
0
def handle_topicchg(event, message):
    chan_name, who, ts, topic = message.parameters
    chan = Channel.findByName(chan_name)
    if (chan is None): return
    chan.setTopic(topic, who, ts)
コード例 #16
0
def handle_sjoin(event, message):
	chan_name=message.parameters[1]
	timestamp=message.parameters[0]
	chan=Channel.findByName(chan_name)
	if(chan is None):
		chan=Channel(chan_name, timestamp)
		Channel.addChannel(chan)
	p_idx=2
	if(message.parameters[p_idx][0]=="+"):
		#we have modes
		if(chan.timestamp==timestamp):
			#merge modes
			chan.setModes(message.parameters[p_idx], message.parameters[p_idx+1:-1], True)
		elif(chan.timestamp>timestamp):
			#clear existing modes and use sjoin modes
			chan.clearModes()
			chan.setModes(message.parameters[p_idx], message.parameters[p_idx+1:-1])
		#else ignore sjoin modes
	
	new_modes=[]
	new_params=[]
	for item in message.parameters[-1].split():
		#this could be a channel member, ban, exemption, or invex -- very confusing!
		# *~@%+ are user statuses qaohv, respectively
		# & is a ban, " is an exemption, ' is an invex
		item_type=item[0]
		if(sjoin_prefix_to_mode.has_key(item_type)):
			item=item[1:]
			new_modes.append(sjoin_prefix_to_mode[item_type])
			new_params.append(item)
		
		if(not sjoin_prefix_to_mode.has_key(item_type) or item_type in ("*", "~", "@", "%", "+")):
			member=Client.findByNick(item)
			if(not member is None):
				log.debug("SJOIN: %s to %s", member.nick, chan.name)
				chan.addClient(member)
	
	if(len(new_modes)>0): chan.setModes("+"+"".join(new_modes), new_params)
コード例 #17
0
def handle_sjoin(event, message):
    chan_name = message.parameters[1]
    timestamp = message.parameters[0]
    chan = Channel.findByName(chan_name)
    if (chan is None):
        chan = Channel(chan_name, timestamp)
        Channel.addChannel(chan)
    p_idx = 2
    if (message.parameters[p_idx][0] == "+"):
        #we have modes
        if (chan.timestamp == timestamp):
            #merge modes
            chan.setModes(message.parameters[p_idx],
                          message.parameters[p_idx + 1:-1], True)
        elif (chan.timestamp > timestamp):
            #clear existing modes and use sjoin modes
            chan.clearModes()
            chan.setModes(message.parameters[p_idx],
                          message.parameters[p_idx + 1:-1])
        #else ignore sjoin modes

    new_modes = []
    new_params = []
    for item in message.parameters[-1].split():
        #this could be a channel member, ban, exemption, or invex -- very confusing!
        # *~@%+ are user statuses qaohv, respectively
        # & is a ban, " is an exemption, ' is an invex
        item_type = item[0]
        if (sjoin_prefix_to_mode.has_key(item_type)):
            item = item[1:]
            new_modes.append(sjoin_prefix_to_mode[item_type])
            new_params.append(item)

        if (not sjoin_prefix_to_mode.has_key(item_type)
                or item_type in ("*", "~", "@", "%", "+")):
            member = Client.findByNick(item)
            if (not member is None):
                log.debug("SJOIN: %s to %s", member.nick, chan.name)
                chan.addClient(member)

    if (len(new_modes) > 0):
        chan.setModes("+" + "".join(new_modes), new_params)