Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###########################################################################
- ## File : xcmd.py ##
- ## Descriptions: ##
- ## This is module is needed in addition to run cellinux-bot-main.py ##
- ## This modul is a modul to contain external commands for the main ##
- ## program. -Why would you want to put all the bot's command in external ##
- ## module ??- The answer is quite simple. We want to be able to edit and ##
- ## reload some commands without restarting the bot's main process, so ##
- ## this is one of our solution. ##
- ## ##
- ## -Main credit goes to: - Poeticartist1 (Shows me the idea) ##
- ## - PIKS (Shows me the way) ##
- ###########################################################################
- import imp
- import threading
- import random
- import os
- import re
- import sys
- import coloring
- import codecs
- import traceback
- import datetime
- import ch
- import release
- import urllib
- import time
- from xfunc import *
- import xfunc as exter
- import coloring
- import __future__
- #############################
- ## urllib secondary import ##
- if sys.version_info[0] > 2:
- import urllib.request as urlreq
- else:
- import urllib2 as urlreq
- #############################
- ##########################
- ## Reading txt database ##
- blacklist = dict()
- try:
- f = open("blacklist.txt", "r")
- blacklist = eval(f.read())
- f.close()
- except:pass
- ranker = dict()
- try:
- f = open("ranker.txt", 'r')
- ranker = eval(f.read())
- f.close()
- except:pass
- rooms = []
- file = open("rooms.txt", 'r')
- for name in file.readlines():
- if len(name.strip()) > 0 :
- rooms.append(name.strip())
- print("NOTICE: Room list loaded.")
- file.close()
- locks = []
- file = open("locks.txt", 'r')
- for name in file.readlines():
- if len(name.strip()) > 0 :
- locks.append(name.strip())
- print("NOTICE: Locked Rooms loaded.")
- file.close()
- ## finished reading database ##
- ###############################
- ###############################
- ## Variables ##
- botversion = release.botversion
- botrelease = release.botrelease
- botsys = release.botsys
- command_list = ['help','wl/register','uwl/unregister','bl/blacklist','chain','ubl/unblacklist','unchain','rank','setrank','pm','broadcast','say','reverse/rsay','find','multichat','ban','unban','join','leave','lock','unlock','rooms','save','mods','activate','restrict','lockdown','wake']
- prefix = [">", "~", " "]
- brutalpic = ["http://i.imgur.com/mdymM8t.jpg","http://i2.kym-cdn.com/photos/images/newsfeed/001/081/950/81b.jpg","http://s.quickmeme.com/img/f8/f8c1380e46d88b4edd02415b11f43824a1ab06c031c1dac09a162ca5384ddc33.jpg","http://ci.memecdn.com/181/9181181.jpg","http://ci.memecdn.com/925/4752925.jpg","http://stream1.gifsoup.com/view2/3452958/nathan-explosion-no-o.gif","http://ci.memecdn.com/930/8323930.jpg","http://cdn.gagbay.com/2014/10/please_prove_that_you_are_brutal-510617.jpg","http://i1.kym-cdn.com/photos/images/facebook/000/872/117/2a8.png","http://i.imgur.com/ZYrFkCw.jpg"]
- nonbrutalpic = ["http://www.agrinionews.gr/wp-content/uploads/2016/01/80b.jpg","http://static4.fjcdn.com/comments/Source+is+metalocalypse+not+reddit+c+mon+_7e7ff5ab89ca355f3f891477285fec03.jpg","http://s-media-cache-ak0.pinimg.com/236x/24/10/7a/24107a5be1191a1242bc0021d7349031.jpg","http://media.giphy.com/media/scoHe0Cw79cK4/giphy.gif","http://www.quickmeme.com/img/b8/b815678dcd584fed11c7f82a8f0ce772ac0bf238dae5bcbc54b2d1c3078a7931.jpg","http://s2.quickmeme.com/img/4d/4d213474085cc2bd23479a01f8b0f893e36965d110abd595eecd1df2634fdb96.jpg"]
- ## Variable Finished ##
- ###############################
- ###############################
- ## Some Functions ##
- def saveAll(self):
- room = self._Room
- f = open("ranker.txt", "w")
- f.write(str(ranker))
- f.close()
- f = open("blacklist.txt", "w")
- f.write(str(blacklist))
- f.close()
- f = open("locks.txt", "w")
- f.write("\n".join(locks))
- f.close()
- f = open("rooms.txt", "w")
- f.write("\n".join(self.roomnames))
- f.close()
- def onPMMessage(self, pm, user, body):
- if body != "":
- pm.message(user, body)
- def onMessage(self, room, user, message):
- try:
- if user.name == self.user.name:return
- uTarget = None
- global uTarget
- global interval_task
- def urank(target):
- if target == None:
- return 0
- if target not in ranker:
- return 0
- rank = ranker[target]
- if rank == 1 and room.getLevel(ch.User(target)) == 1:
- rank = 2
- if rank == 1 and room.getLevel(ch.User(target)) == 2:
- rank = 3
- return rank
- def utitle(target):
- drank = urank(target)
- title = "null"
- if drank > 0:
- if drank == 1:
- title = "player"
- if drank == 2:
- title = "room moderator"
- if drank == 3:
- title = "room admin"
- if drank == 4:
- title = "MODERATOR"
- if drank == 5:
- title = "OWNER"
- return title
- myrank = urank(user.name)
- hisrank = urank(uTarget)
- mytitle = utitle(user.name)
- seth = self
- global seth
- saveAll(seth)
- from coloring import colorTest as ctp
- from coloring import colorLite as clp
- from coloring import colorBold as cbp
- def ct(col):
- return ctp(seth, col)
- def cl(term):
- return clp(seth, term)
- def cb(term):
- return cbp(seth, term)
- global myrank
- global hisrank
- global mytitle
- def roomUsers():
- usrs = []
- gay = []
- prop = 0
- prop = prop + len(room._userlist) - 1
- for i in room._userlist:
- i = str(i)
- usrs.append(i)
- while prop >= 0:
- j = usrs[prop].replace("<User: ", "")
- i = j.replace(">", "")
- gay.append(i)
- prop = prop - 1
- return gay
- def getParticipant(arg):
- rname = self.getRoom(arg)
- usrs = []
- gay = []
- finale = []
- prop = 0
- prop = prop + len(rname._userlist) - 1
- for i in rname._userlist:
- i = str(i)
- usrs.append(i)
- while prop >= 0:
- j = usrs[prop].replace("<User: ", "")
- i = j.replace(">", "")
- gay.append(i)
- prop = prop - 1
- for j in gay:
- if j not in finale:
- finale.append(j)
- return finale
- def pars(args):
- args=args.lower()
- userlist = roomUsers()
- for name in userlist:
- if args in name:return name
- def roompars(args):
- args = args.lower()
- for name in self.roomnames:
- if args in name:return name
- if message.body[0] in prefix: #prefix usage in this line (for this case I use "*" as prefix)
- data = message.body[1:].split(" ", 1) #This part splits message body into [0]prefix and [1:]data ([1:] <- this means the message body's second character and after) and data will be split into 2 (cmd(data[0]), args(data[1])) which is very usefull. (Many thanks to TryHardHusky)
- if len(data) == 2: #If there are more than 1 data (This is where we will get args)
- cmd, args = data[0], data[1] #the first data (data[0]) will be the cmd (specified command) and the next data will be args (it doesn't matter how many word next to the cmd, It'd eventually be args)
- else: #If there is only 1 data (No args)
- cmd, args = data[0], "" #the arg will simply be "" (Empty)
- cmd == cmd.lower()
- if cmd == "brutal":
- fin = random.randint(1,2)
- if fin == 1:
- pic = random.choice(["http://i.imgur.com/mdymM8t.jpg","http://i2.kym-cdn.com/photos/images/newsfeed/001/081/950/81b.jpg","http://s.quickmeme.com/img/f8/f8c1380e46d88b4edd02415b11f43824a1ab06c031c1dac09a162ca5384ddc33.jpg","http://ci.memecdn.com/181/9181181.jpg","http://ci.memecdn.com/925/4752925.jpg","http://stream1.gifsoup.com/view2/3452958/nathan-explosion-no-o.gif","http://ci.memecdn.com/930/8323930.jpg","http://cdn.gagbay.com/2014/10/please_prove_that_you_are_brutal-510617.jpg","http://i1.kym-cdn.com/photos/images/facebook/000/872/117/2a8.png","http://i.imgur.com/ZYrFkCw.jpg"])
- room.message(" "+pic)
- else:
- pic = random.choice(["http://www.agrinionews.gr/wp-content/uploads/2016/01/80b.jpg","http://static4.fjcdn.com/comments/Source+is+metalocalypse+not+reddit+c+mon+_7e7ff5ab89ca355f3f891477285fec03.jpg","http://s-media-cache-ak0.pinimg.com/236x/24/10/7a/24107a5be1191a1242bc0021d7349031.jpg","http://media.giphy.com/media/scoHe0Cw79cK4/giphy.gif","http://www.quickmeme.com/img/b8/b815678dcd584fed11c7f82a8f0ce772ac0bf238dae5bcbc54b2d1c3078a7931.jpg","http://s2.quickmeme.com/img/4d/4d213474085cc2bd23479a01f8b0f893e36965d110abd595eecd1df2634fdb96.jpg"])
- room.message(" "+pic)
- if cmd == "ival":
- if myrank < 3:
- room.message(cb("red!Jangan harap."), True)
- return
- interval_task = room._ivalTasks
- args = args.split(" ", 1)
- if args[0] == "kill":
- if len(args) == 2:
- if args[1] in interval_task:
- self._tasks.remove(interval_task[args[1]][0])
- room.message("Task killed: "+str(args[1])+" - "+str(interval_task[args[1]][0]))
- interval_task.pop(args[1])
- if args[0] == "tasks":
- if len(interval_task) > 0:
- tasklist = []
- for i in interval_task:
- _task = interval_task
- tasklist.append("(Name: "+str(i)+" - (every "+str(_task[i][1])+" seconds) post "+str(_task[i][2])+" ["+str(_task[i][0])+"])")
- room.message(", ".join(tasklist))
- if args[0] not in ["kill", "tasks"]:
- if len(args) > 1:
- task_name = args[0]
- ivaltime, task_output = args[1].split(" ", 1)
- task_interval_time = int(ivaltime)
- task = self.setInterval(task_interval_time, room.message, str(task_output))
- interval_task.update({task_name:[task, ivaltime, task_output]})
- room.message("task created: "+str(task_name)+" ("+str(ivaltime)+" seconds interval)")
- if (cmd == "ee") and urank(user.name) == 5: #DO NOT MESS WITH THIS COMMAND IF YOU DON'T KNOW WHAT YOU'RE DOING (This is a vital command)
- ret = eval(args)
- if ret == None:
- room.message("Done.")
- return
- room.message(str(ret))
- if cmd == "setrank" and urank(user.name) == 5:
- help_output = "Usage : ~setrank [usertarget] [number]<br/>Example : ~setrank gayman 1]"
- if args == "":
- room.message(help_output, True)
- if args != "":
- try:
- args = args.lower()
- target, rank = args.split(" ", 1)
- target = str(target)
- rank = int(rank)
- available_rank = [-1,0,1,4,5]
- if not rank in available_rank:
- room.message("Type a propper rank number.")
- return
- if rank == 1:
- if urank(target) == 1:
- room.message("Why ??? they are rank 1 you know !!")
- return
- room.message(target.title()+"'s rank is set to: "+str(rank)+" [Player]")
- if rank == 4:
- if urank(target) == 4:
- room.message(target.title()+" is already a Moderator.")
- return
- room.message(target.title()+"'s rank is set to: "+str(rank)+" [Moderator]")
- if rank == 5:
- if not user.name == "0rx": return #put your name there (if user.name == "yourname" and user.name == "anothername":) To prevent other Owners(in this case is Co-Owners) to set user's rank to Co-Owner.
- if urank(target) == 5:
- room.message(target.title()+" is already a Co-Owner.")
- return
- room.message(target.title()+"'s rank is set to: "+str(rank)+" [Owner]")
- if rank == 0:
- if target == "0rx": return
- if target in ranker:
- ranker.pop(target)
- if target in blacklist:
- blacklist.pop(target)
- room.message(target.title()+"'s rank is set to: "+str(rank))
- return
- if rank == -1:
- if target == "0rx": return
- if target in blacklist:
- room.message(target.title()+" is already blacklisted.<br/>Reason: %s"% blacklist[target])
- return
- blacklist.update({target:"Annoying reason."})
- room.message(target.title()+"'s rank is set to: "+str(rank)+" [Fugitive]")
- return
- if target in blacklist:
- blacklist.pop(target)
- ranker.update({target:rank})
- except:
- room.message(help_output, True)
- except Exception as e:
- try:
- et, ev, tb = sys.exc_info()
- lineno = tb.tb_lineno
- fn = tb.tb_frame.f_code.co_filename
- room.message("[Error] %s Line %i - %s"% (fn, lineno, str(e)))
- return
- except:
- room.message("Undescribeable error detected !!")
- return
Advertisement
Add Comment
Please, Sign In to add comment