예제 #1
0
    def example_function(self,receiver):
	try:
		while True:
                        print "Check";
                        msg = (yield)
                        act = Action();
                        print('Full dump: {array}'.format(array=str( msg )))
		
			if (msg.event == 'message'):
				if (hasattr(msg.sender,'username')):
					user = User.byTguser(msg.sender.username);
	
			                if user is not None:
		        	                displayUser = str(user.name);
					else:
						displayUser = str(msg.sender.name);
				else:
					displayUser = str(msg.sender.name);
					msg.sender.username = '******';
	
	
	
				msg.text = self.strip_non_ascii(msg.text);
				if (msg.receiver and str(msg.receiver.name) == Config.get("gateway","tggroup1") and msg.text[0:5] != '[IRC:' and msg.text[0:4] != '[WA:' and msg.text[0:4] != '[TG:' ):
					print "Send message to " + Config.get("gateway","ircchan1");
					self.actions = Action.privmsg(act,"[TG:"+displayUser+"] " + (msg.text.encode('utf_8','ignore')) , Config.get("gateway","ircchan1"))
					self.executeCommand(msg.text.encode('utf_8','ignore'),Config.get("gateway","ircchan1"),str(msg.sender.username));
	
				if (msg.receiver and str(msg.receiver.name) == Config.get("gateway","tggroup2") and msg.text[0:5] != '[IRC:' and msg.text[0:4] != '[WA:' and msg.text[0:4] != '[TG:' ):
					print "Send message to " + Config.get("gateway","ircchan2");
					self.actions = Action.privmsg(act,"[TG:"+displayUser+"] " + (msg.text.encode('utf_8','ignore')) , Config.get("gateway","ircchan2"))
					self.executeCommand(msg.text.encode('utf_8','ignore'),Config.get("gateway","ircchan2"),str(msg.sender.username));
	
				if (msg.receiver and str(msg.receiver.name) == Config.get("gateway","tggroup3") and msg.text[0:5] != '[IRC:' and msg.text[0:4] != '[WA:' and msg.text[0:4] != '[TG:' ):
					print "Send message to " + Config.get("gateway","ircchan3");
					self.actions = Action.privmsg(act,"[TG:"+displayUser+"] " + (msg.text.encode('utf_8','ignore')) , Config.get("gateway","ircchan3"))
					self.executeCommand(msg.text.encode('utf_8','ignore'),Config.get("gateway","ircchan3"),str(msg.sender.username));
			else:
				print "Not A Message";

	except AttributeError:
		print sys.exc_info();
		print "Nothing we need to worry about...";
		receiver.stop();
		self.checkTG();
	except UnicodeEncodeError:
		print "Characters we can't deal with!";
	except KeyboardInterrupt:
		receiver.stop()
		print("Exiting")
예제 #2
0
    def executeCommand(self,msg,channel,tguser):
	from Core.callbacks import Callbacks
	from Core.actions import Action

	user = User.byTguser(tguser);
	if (msg[0:1] == '%'):
		if (msg == '%whoami'):

			if (tguser == 'nouser'):

				message = Action();
				message.privmsg("You don't have a TG username you donut! Read https://telegram.org/faq#q-what-are-usernames-how-do-i-get-one before you bother me again!",channel);
	                        if (channel == Config.get('gateway','ircchan1')):
        	                        self.sendToTG(Config.get('gateway','tggroup1'),"You don't have a TG username you donut! Read https://telegram.org/faq#q-what-are-usernames-how-do-i-get-one before you bother me again!");
                	        if (channel == Config.get('gateway','ircchan2')):
                        	        self.sendToTG(Config.get('gateway','tggroup2'),"You don't have a TG username you donut! Read https://telegram.org/faq#q-what-are-usernames-how-do-i-get-one before you bother me again!");
	                        if (channel == Config.get('gateway','ircchan3')):
        	                        self.sendToTG(Config.get('gateway','tggroup3'),"You don't have a TG username you donut! Read https://telegram.org/faq#q-what-are-usernames-how-do-i-get-one before you bother me again!");

			else:
				message = Action();
				message.privmsg("Your TG username is "+tguser+". If you havn't already, you need to add this to the bot using .pref tguser="******"");
	                        if (channel == Config.get('gateway','ircchan1')):
	                                self.sendToTG(Config.get('gateway','tggroup1'),"Your TG username is "+tguser+". If you havn't already, you need to add this to the bot using .pref tguser="******"");
	                        if (channel == Config.get('gateway','ircchan2')):
	                                self.sendToTG(Config.get('gateway','tggroup2'),"Your TG username is "+tguser+". If you havn't already, you need to add this to the bot using .pref tguser="******"");
	                        if (channel == Config.get('gateway','ircchan3')):
	                                self.sendToTG(Config.get('gateway','tggroup3'),"Your TG username is "+tguser+". If you havn't already, you need to add this to the bot using .pref tguser="******"");
				


		elif (user is None):
			message = Action();
			message.privmsg("You must be registered with BowBot and have your TG user set to send commands from TG",channel);
			if (channel == Config.get('gateway','ircchan1')):
				self.sendToTG(Config.get('gateway','tggroup1'),"You must be registered with BowBot and have your TG user set to send commands from TG");
			if (channel == Config.get('gateway','ircchan2')):
                                self.sendToTG(Config.get('gateway','tggroup2'),"You must be registered with BowBot and have your TG user set to send commands from TG");
			if (channel == Config.get('gateway','ircchan3')):
                                self.sendToTG(Config.get('gateway','tggroup3'),"You must be registered with BowBot and have your TG user set to send commands from TG");

			
		else:
			msg = '!' + msg.lstrip("%");
			line = ":"+str(user.name)+"!~"+str(user.name)+"@"+str(user.name)+".users.netgamers.org PRIVMSG "+channel+" :"+msg+"";
			message = Action()
			message.parse(line);
			callback = Callbacks.callback(message);