mirror of
https://github.com/vgstation-coders/vgstation13.git
synced 2025-12-10 02:16:05 +00:00
Added CC-Nanotrasen, an IRC bot made by Skibiliano and given to us by him under CC-BY-SA 3.0 licensing WHAT DOES THIS MEAN? It means all servers running this SVN now have the option to use an easy to configure IRC bot capable of relaying adminhelps from ingame to the server/channel of their choice. - Runs on python 2.6 scripts with psyco support - Relaying can be toggled from config.txt (so you don't runtime with every adminhelp if you decide not to use it) - Comes with a bunch of other useful and fun tools too - Added a new global proc, send2irc(msg,msg2) YOU'LL NEVER GUESS WHAT IT DOES CONSIDERING WHAT I JUST MENTIONED ----msg and msg2 are just what text gets relayed to irc, separated by a |, for instance send2irc(hello, world) would come out as "CC_NanoTrasen: Hello | World git-svn-id: http://tgstation13.googlecode.com/svn/trunk@2783 316c924e-a436-60f5-8080-3fe189b3f50e
133 lines
5.6 KiB
Python
133 lines
5.6 KiB
Python
from urllib2 import urlopen
|
|
import os
|
|
import pickle
|
|
from CORE_DATA import directory,no_absolute_paths
|
|
global did_tell, no_absolute_paths
|
|
no_absolute_paths = True
|
|
did_tell = False
|
|
def YTCV4(youtube_url,cache=1,debug=0):
|
|
global did_tell, no_absolute_paths
|
|
Do_not_open = True
|
|
__doc__ = "Cache does not affect anything, it's legacy for skibot."
|
|
try:
|
|
cut_down = youtube_url.split("watch?v=")[1].split("&")[0]
|
|
if len(cut_down) > 11: #Longer than normal, presume troll.
|
|
youtube_url.replace(cut_down,cut_down[:11])
|
|
elif len(cut_down) < 11: #Shorter than normal
|
|
pass
|
|
except IndexError:
|
|
return "Reflex: Where's the watch?v=?"
|
|
first_two = cut_down[0:2]
|
|
try:
|
|
if no_absolute_paths:
|
|
tiedosto = open("YTCache/"+first_two+".tcc","r")
|
|
else:
|
|
tiedosto = open(directory+"YTCache/"+first_two+".tcc","r")
|
|
except:
|
|
prev_dict = {}
|
|
else:
|
|
try:
|
|
prev_dict = pickle.load(tiedosto)
|
|
except EOFError: # Cache is corrupt
|
|
os.remove(directory+"/nano/"+tiedosto.name)
|
|
print "REMOVED CORRUPT CACHE: "+tiedosto.name
|
|
prev_dict = {}
|
|
tiedosto.close() # I think this should belong here.
|
|
if cut_down in prev_dict.keys():
|
|
return prev_dict[cut_down]
|
|
else:
|
|
pass
|
|
try:
|
|
if no_absolute_paths:
|
|
tiedosto = open("YTCache/"+first_two+".tcc","w")
|
|
else:
|
|
tiedosto = open(directory+"YTCache/"+first_two+".tcc","w")
|
|
except IOError,error:
|
|
if len(prev_dict.keys()) > 0:
|
|
try:
|
|
tiedosto = open(directory+"YTCache/"+first_two+".tcc","w") #This is a Just In Case
|
|
except IOError:
|
|
if did_tell == False:
|
|
did_tell = True
|
|
return "COULD NOT ACCESS FILE "+first_two+".tcc! The next time you run this link, it checks it through the web"
|
|
Do_not_open = False
|
|
else:
|
|
did_tell = False
|
|
pickle.dump(prev_dict,tiedosto)
|
|
tiedosto.close()
|
|
else:
|
|
pass
|
|
return "Very odd error occurred: " + str(error)
|
|
youtube_url = youtube_url.replace("http//","http://")
|
|
if youtube_url.lower()[0:7] != "http://" and youtube_url[0:4] == "www.":
|
|
youtube_url = "http://" + youtube_url
|
|
if youtube_url.count("/") + youtube_url.count("\\") < 3:
|
|
if len(prev_dict.keys()) > 0:
|
|
if Do_not_open == True:
|
|
tiedosto = open(directory+"YTCache/"+first_two+".tcc","w") #This is a Just In Case
|
|
pickle.dump(prev_dict,tiedosto)
|
|
tiedosto.close()
|
|
else:
|
|
pass
|
|
return "Reflex: Video cannot exist"
|
|
else:
|
|
if "http://" in youtube_url[0:12].lower() and youtube_url[0:7].lower() != "http://":
|
|
youtube_url = youtube_url[youtube_url.find("http://"):]
|
|
elif youtube_url[0:7].lower() != "http://":
|
|
if len(prev_dict.keys()) > 0:
|
|
if Do_not_open == True:
|
|
tiedosto = open(directory+"YTCache/"+first_two+".tcc","w") #This is a Just In Case
|
|
pickle.dump(prev_dict,tiedosto)
|
|
tiedosto.close()
|
|
return "Reflex: Incorrect link start"
|
|
if "?feature=player_embedded&" in youtube_url:
|
|
youtube_url = youtube_url.replace("?feature=player_embedded&","?")
|
|
try:
|
|
website = urlopen(youtube_url)
|
|
except:
|
|
if len(prev_dict.keys()) > 0:
|
|
if Do_not_open == True:
|
|
tiedosto = open(directory+"YTCache/"+first_two+".tcc","w") #This is a Just In Case
|
|
pickle.dump(prev_dict,tiedosto)
|
|
tiedosto.close()
|
|
else:
|
|
pass
|
|
return "Reflex: Incorrect link!"
|
|
for i in website.readlines():
|
|
if i.count('<meta name="title" content') == 1:
|
|
if type(i[30:-3]) != str:
|
|
if Do_not_open == True:
|
|
tiedosto = open(directory+"YTCache/"+first_two+".tcc","w") #This is a Just In Case
|
|
prev_dict[cut_down] = "No title for video"
|
|
pickle.dump(prev_dict,tiedosto)
|
|
tiedosto.close()
|
|
return "Video deleted"
|
|
else:
|
|
#result = i[30:-3]
|
|
contentvar = i.find('content="')
|
|
result = i[contentvar+5:i.find('">',contentvar)]
|
|
if "&quot;" in result:
|
|
result = result.replace("&quot;",'"')
|
|
else:
|
|
pass
|
|
if "&amp;" in result:
|
|
result = result.replace("&amp;","&")
|
|
else:
|
|
pass
|
|
if "&#39;" in result:
|
|
result = result.replace("&#39;","'")
|
|
else:
|
|
pass
|
|
if Do_not_open == True:
|
|
tiedosto = open(directory+"YTCache/"+first_two+".tcc","w") #This is a Just In Case
|
|
prev_dict[cut_down] = result
|
|
pickle.dump(prev_dict,tiedosto)
|
|
tiedosto.close()
|
|
return result
|
|
if Do_not_open == True:
|
|
tiedosto = open(directory+"YTCache/"+first_two+".tcc","w") #This is a Just In Case
|
|
prev_dict[cut_down] = "No title for video, Removed / Needs Age verification / Does not exist"
|
|
pickle.dump(prev_dict,tiedosto)
|
|
tiedosto.close()
|
|
return "No title for video, Removed / Needs age verification / Does not exist"
|