def eventLogged(data): print(data) name = data[1] # print name ip = data[2].split(':')[0] #tweetmessage = urllib.urlencode({"status": name + " " + message}) #response = json.loads(oauth_req( "https://api.twitter.com/1.1/statuses/update.json?" + tweetmessage, AccessToken, AccessTokenSecret, http_method="POST")) #print response try: for each in open( otherdata + "/motd.txt", "r" ).readlines(): time.sleep(1) message = "/tellraw " + name + " " + showandtellraw.tojson( each.strip() ) vanillabean.send( message ) except: pass conn = sqlite3.connect(dbfile, detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) cur = conn.cursor() cur.execute("SELECT * FROM maildrop WHERE inverted = 0 and slots > 0 and name = ? COLLATE NOCASE", (name,)) maildrop = cur.fetchall() cur.execute("SELECT * FROM maildrop WHERE inverted = 1 and slots = 0 and name = ? COLLATE NOCASE", (name,)) maildropinv = cur.fetchall() for mail in maildrop + maildropinv: dimcoords, boxname, desc, slots, hidden, inverted = mail dim, coords = dimcoords.split(",",1) if dim == "e": worldnum = "1" elif dim == "n": worldnum = "2" elif dim == "o": worldnum = "0" URLcoords = coords.replace(",", "/") toserver = '/tellraw ' + boxname + ' ' + showandtellraw.tojson(serverName + ' {{Maildrop [_{}_|http://{}/map/#/{}/-1/{}/0]~{} {}}} {}'.format(desc if desc else "{} {}".format(worlddict[dim][0], coords), URL, URLcoords, worldnum, worlddict[dim][0], coords, "has {} items".format(slots) if slots else "is empty") ) vanillabean.send( toserver ) print(toserver) q.put(('insert into joins values (?,?,?,?)', (datetime.datetime.now(), name, UUID.get(name, "Unknown"), ip))) conn.commit() conn.close()
def sendMaildrops(): conn = sqlite3.connect(dbfile) cur = conn.cursor() cur.execute( "SELECT * FROM maildrop natural join onlineplayers WHERE inverted = 0 and slots > 0 COLLATE NOCASE" ) maildrop = cur.fetchall() cur.execute( "SELECT * FROM maildrop natural join onlineplayers WHERE inverted = 1 and slots = 0 COLLATE NOCASE" ) maildropinv = cur.fetchall() for mail in maildrop + maildropinv: dimcoords, boxname, desc, slots, hidden, inverted = mail dim, coords = dimcoords.split(",", 1) URLcoords = coords.replace(",", "/") toserver = '/tellraw ' + boxname + ' ' + showandtellraw.tojson( serverName + ' {{Maildrop [_{}_|http://{}/map/#/{}/-1/{}/0]~{} {}}} {}'.format( desc if desc else "{} {}".format(worlddict[dim][0], coords), URL, URLcoords, worlddict[dim][1], worlddict[dim][0], coords, "has {} items".format(slots) if slots else "is empty")) #vanillabean.send( toserver ) # print(toserver) conn.commit() conn.close()
def sendMaildrops(): conn = sqlite3.connect(dbfile) cur = conn.cursor() cur.execute("SELECT * FROM maildrop natural join onlineplayers WHERE inverted = 0 and slots > 0 COLLATE NOCASE") maildrop = cur.fetchall() cur.execute("SELECT * FROM maildrop natural join onlineplayers WHERE inverted = 1 and slots = 0 COLLATE NOCASE") maildropinv = cur.fetchall() for mail in maildrop + maildropinv: dimcoords, boxname, desc, slots, hidden, inverted = mail dim, coords = dimcoords.split(",",1) if dim == "e": worldnum = "1" elif dim == "n": worldnum = "2" elif dim == "o": worldnum = "0" URLcoords = coords.replace(",", "/") toserver = '/tellraw ' + boxname + ' ' + showandtellraw.tojson(serverName + ' {{Maildrop [_{}_|http://{}/map/#/{}/-1/{}/0]~{} {}}} {}'.format(desc if desc else "{} {}".format(worlddict[dim][0], coords), URL, URLcoords, worldnum, worlddict[dim][0], coords, "has {} items".format(slots) if slots else "is empty") ) vanillabean.send( toserver ) print(toserver) conn.commit() conn.close()
def tellcoords( coords ): for each in coords: print(each, each[0], each[1], each[2]) vanillabean.send("/tellraw @a " + showandtellraw.tojson(serverName + " [Map: _{} {}_|http://{}/map/#/{}/64/{}/-3/{}/0]".format(worlddict[ each[0].lower() ][0], ", ".join([each[1], each[2]]), URL, each[1], each[2], worlddict[ each[0].lower() ][1])))
def tellcoords( coords ): worlddict = { "o" : ["overworld", "0"], "n" : ["nether", "2"], "e" : ["end", "1"] } for each in coords: print (each, each[0], each[1], each[2]) vanillabean.send("/tellraw @a " + showandtellraw.tojson(serverFormat.format(servername) + "[Map: _" + worlddict[ each[0].lower() ][0] + " " + each[1] + ', ' + each[2] + "_|http://" + URL + "/map/#/" + each[1] + "/64/" + each[2] + "/-3/" + worlddict[ each[0].lower() ][1] + "/0]"))
def updateStreaming(bool): global streaming if bool == streaming: pass elif bool == True: streaming = True vanillabean.send( "/scoreboard teams join Twitch greener_ca" ) jsontext = showandtellraw.tojson("<aqua^\<><dark_purple^twitch><aqua^\>> you are streaming") vanillabean.send("/tellraw greener_ca " + jsontext) logging.debug("Started streaming") else: streaming = False vanillabean.send( "/scoreboard teams leave Twitch greener_ca" ) jsontext = showandtellraw.tojson("<aqua^\<><dark_purple^twitch><aqua^\>> you are NOT streaming") vanillabean.send("/tellraw greener_ca " + jsontext) logging.debug("Stopped streaming")
def maildropPage(page): if page: cur.execute("SELECT * FROM maildrop WHERE name = ? COLLATE NOCASE limit ?, ?", (name, (page - 1) * 5, 5)) maildrop = cur.fetchall() vanillabean.send("/tellraw {} ".format(name) + showandtellraw.tojson("{} <yellow^--- {} maildrop(s) - page {} of {} - \(!maildrop \<page\>\) --->".format(serverName, total, page, totalPages))) for mail in maildrop: dimcoords, boxname, desc, slots, hidden, inverted = mail dim, coords = dimcoords.split(",",1) URLcoords = coords.replace(",", "/") toserver = '/tellraw ' + boxname + ' ' + showandtellraw.tojson(serverName + ' {{Maildrop [_{}_|http://{}/map/#/{}/-1/{}/0]~{} {}}} {}'.format(desc if desc else "{} {}".format(worlddict[dim][0], coords), URL, URLcoords, worlddict[dim][1], worlddict[dim][0], coords, "has {} items".format(slots) if slots else "is empty") ) vanillabean.send( toserver ) print(toserver) else: pass
def tellcoords(coords): for each in coords: print(each, each[0], each[1], each[2]) vanillabean.send("/tellraw @a " + showandtellraw.tojson( serverName + " [Map: _{} {}_|http://{}/map/#/{}/64/{}/-3/{}/0]".format( worlddict[each[0].lower()][0], ", ".join([each[1], each[2]]), URL, each[1], each[2], worlddict[each[0].lower()][1])))
def chatUpdate(): global streaming global debug global createTime while True: time.sleep(5 * 60) if streaming or debug: logging.debug("Updating chat") text = "<aqua^\<><dark_purple^twitch><aqua^\>> {}\/{} started {}".format(viewers, len(followers), pretty_date(time=createTime)) logging.debug(text) vanillabean.send("/tellraw greener_ca " + showandtellraw.tojson(text))
def eventLogged(data): print(data) name = data[1] # print name ip = data[2].split(':')[0] #tweetmessage = urllib.urlencode({"status": name + " " + message}) #response = json.loads(oauth_req( "https://api.twitter.com/1.1/statuses/update.json?" + tweetmessage, AccessToken, AccessTokenSecret, http_method="POST")) #print response token = ''.join( random.choice(string.ascii_uppercase + string.digits) for _ in range(5)) try: for each in open(otherdata + "/motd.txt", "r").readlines(): time.sleep(1) message = "/tellraw " + name + " " + showandtellraw.tojson( each.strip().replace("verifykey", token)) vanillabean.send(message) except: pass ''' maildrop = dbQuery(dbfile, 30, ("SELECT * FROM maildrop WHERE inverted = 0 and slots > 0 and name = ? COLLATE NOCASE", (name,))) maildropinv = dbQuery(dbfile, 30, ("SELECT * FROM maildrop WHERE inverted = 1 and slots = 0 and name = ? COLLATE NOCASE", (name,))) for mail in maildrop + maildropinv: dimcoords, boxname, desc, slots, hidden, inverted = mail dim, coords = dimcoords.split(",",1) if dim == "e": worldnum = "1" elif dim == "n": worldnum = "2" elif dim == "o": worldnum = "0" URLcoords = coords.replace(",", "/") toserver = '/tellraw ' + boxname + ' ' + showandtellraw.tojson(serverName + ' {{Maildrop [_{}_|http://{}/map/#/{}/-1/{}/0]~{} {}}} {}'.format(desc if desc else "{} {}".format(worlddict[dim][0], coords), URL, URLcoords, worldnum, worlddict[dim][0], coords, "has {} items".format(slots) if slots else "is empty") ) vanillabean.send( toserver ) print(toserver) ''' q.put(('INSERT INTO joins VALUES (?,?,?,?)', (datetime.datetime.now(), name, UUID.get(name, "Unknown"), ip))) q.put(('REPLACE INTO discordverify (name, token) VALUES (?, ?)', (name, token)))
def tellcoords(coords): worlddict = { "o": ["overworld", "0"], "n": ["nether", "2"], "e": ["end", "1"] } for each in coords: print each, each[0], each[1], each[2] vanillabean.send("/tellraw @a " + showandtellraw.tojson( "<green^" + servername + "> [Map: _" + worlddict[each[0].lower()][0] + " " + each[1] + ', ' + each[2] + "_|http://" + URL + "/map/#/" + each[1] + "/64/" + each[2] + "/-3/" + worlddict[each[0].lower()][1] + "/0]"))
def on_message(message): # we do not want the bot to reply to itself if message.author == client.user: return print(message.author.display_name, message.clean_content.encode("utf-8")) if message.channel.is_private: coordscomma = re.findall( "^([EONeon]) (-?\d+), ?(-?\d+)", message.content) if coordscomma: yield from client.send_message(channelobject, coordsmessage( coordscomma )) tellcoords(coordscomma) if message.channel.id == discordChannel: links = re.findall('(https?://\S+)', message.content) display_name = str(message.author.display_name) discordName = str(message.author) messagetext = str(message.clean_content) # messagetext = messagetext.replace('"', r"\"") discordtext = u'{"text" : "\\u2689 ", "color" : "blue" }' print([a.name for a in message.author.roles]) if message.author.bot: nameFormat = '<blue^\<>{{<green^{}>~{}}}<blue^\>> ' mcplayer, mcmessage = messagetext.split(" ", 1) messagetext = mcplayer.strip('`') + " " + mcmessage elif "patrons" in [a.name for a in message.author.roles]: nameFormat = '<blue^\<>{{<red^{}>~{}}}<blue^\>> ' else: nameFormat = '<blue^\<>{{<white^{}>~{}}}<blue^\>> ' #finalline = '/tellraw @a[team=!mute] {{"text" : "", "extra" : [{}, {{"color" : "gold", "text" : "{} "}}, {{"text" : "{}"}}]}}'.format(discordtext, display_name, messagetext) tellrawText = nameFormat.format(display_name.replace("_", "\_").replace("~",""), discordName.replace("_", "\_").replace("@","\@").replace("~","")) finalline = '/tellraw @a[team=!mute] ' + showandtellraw.tojson(tellrawText, noparse=messagetext) vanillabean.send(finalline) if links: telllinks( links ) if message.channel.id == discordPrivChannel and not message.author.bot: yield from client.send_message(privchannelobject, vanillabean.send(message.content))
def telllinks(links): for each in links: print each vanillabean.send("/tellraw @a " + showandtellraw.tojson("<green^" + servername + "> [_Link_|" + each + "]"))
def telllinks( links ): for each in links: print( each) vanillabean.send("/tellraw @a " + showandtellraw.tojson((serverFormat + " [_Link_|{}]").format(servername, each)))
def on_message(message): worlddict = { "o" : ["overworld", "0"], "n" : ["nether", "2"], "e" : ["end", "1"] } # we do not want the bot to reply to itself if message.author == client.user: return # print(message.author.display_name, message.clean_content.encode("utf-8"), message.attachments) if client.user in message.mentions: print("mentioned") reCoords = re.findall( "(-?\d+,) ?(\d+,)? ?(-?\d+)", message.content) print(reCoords) if reCoords: reDim = re.findall("nether|end|over| o | e | n ", message.content) print(reDim) if reDim: if reDim[0] in ["over", " o "]: dim = "o" elif reDim[0] in ["nether", " n "]: dim = "n" elif reDim[0] in ["end", " e "]: dim = "e" else: dim = "o" yield from client.send_message(message.channel, coordsmessage( reCoords, dim )) tellcoords(reCoords, dim) if message.channel.is_private: if message.content.startswith("/"): command = message.content[1:].split(" ", 1)[0] args = message.content[1:].split(" ", 1)[1:] print(command, args) name = dbQuery(dbfile, 100, ('SELECT name FROM players WHERE discordID = ?', (message.author.id,))) if name: name = name[0][0] print(name, command, args) if command == "link": ign = args[0] server = client.get_server("140194383118073856") member = server.get_member(message.author.id) yield from client.send_message(message.channel, "You have 10 seconds to connect to the server with {}. If you are already connected, please disconnect and reconnect. You will receive a message when you are successful".format(ign)) dbQuery(dbfile, 100, ('INSERT INTO verify (name, discordID) VALUES (?, ?)', (ign, message.author.id))) if command == "mute": if "on" in args: print("yup") vanillabean.send("/scoreboard teams join mute {}".format(name)) vanillabean.send("/tell {} Muting Discord".format(name)) elif "off" in args: vanillabean.send("/scoreboard teams leave mute {}".format(name)) vanillabean.send("/tell {} Un-Muting Discord".format(name)) if command == "maildrop": print("Printing maildrops") maildrop = dbQuery(dbfile, 30, ("SELECT coords, name, desc, slots, hidden, inverted FROM maildrop WHERE name = ? COLLATE NOCASE", (name,))) print(maildrop) if maildrop: toplayer = "Showing maildrops for {}\n".format(name) for mail in maildrop: dimcoords, boxname, desc, slots, hidden, inverted = mail dim, coords = dimcoords.split(",", 1) URLcoords = coords.replace(",", "/") toplayer += ':package: {} {} http://{}/map/#/{}/-1/{}/0\n'.format(desc if desc else "{} {}".format(worlddict[dim][0], coords), "has {} items".format(slots) if slots else "is empty", URL, URLcoords, worlddict[dim][1]) yield from client.send_message(message.channel, toplayer) if message.channel.id == discordChannel: links = re.findall('(https?://\S+)', message.content) display_name = str(message.author.display_name) discordName = str(message.author) messagetext = str(message.clean_content) # messagetext = messagetext.replace('"', r"\"") discordtext = u'{"text" : "\u2689 ", "color" : "blue" }' print([a.name for a in message.author.roles]) if message.author.bot: nameFormat = '<blue^\<>{{<green^{}>~{}}}<blue^\>> ' mcplayer, mcmessage = messagetext.split(" ", 1) messagetext = mcplayer.strip('`') + " " + mcmessage elif "patrons" in [a.name for a in message.author.roles]: nameFormat = '<blue^\<>{{<red^{}>~{}}}<blue^\>> ' else: nameFormat = '<blue^\<>{{<white^{}>~{}}}<blue^\>> ' #finalline = '/tellraw @a[team=!mute] {{"text" : "", "extra" : [{}, {{"color" : "gold", "text" : "{} "}}, {{"text" : "{}"}}]}}'.format(discordtext, display_name, messagetext) tellrawText = nameFormat.format(display_name.replace("_", "\_").replace("~",""), discordName.replace("_", "\_").replace("@","\@").replace("~","")) finalline = '/tellraw @a[team=!mute] ' + showandtellraw.tojson(tellrawText, noparse=messagetext) vanillabean.send(finalline) if links: telllinks( links ) if message.channel.id == discordPrivChannel and not message.author.bot: yield from client.send_message(privchannelobject, vanillabean.send(message.content))
def tellcoords( reCoords, reDim ): worlddict = { "o" : ["overworld", "0"], "n" : ["nether", "2"], "e" : ["end", "1"] } for each in reCoords: vanillabean.send("/tellraw @a " + showandtellraw.tojson(serverFormat.format(servername) + "[Map: _{} {}{}{}_|http://{}/map/#/{}/{}/{}/-3/{}/0]".format(worlddict[reDim][0], each[0], each[1], each[2], URL, each[0].strip(','), each[1].strip(',') if each[1] else "64" , each[2], worlddict[reDim][1])))
def telllinks(links): for each in links: print(each) vanillabean.send("/tellraw @a " + showandtellraw.tojson(serverName + " [_Link_|{}]".format(each)))