diff --git a/plugins/cypher.py b/plugins/cypher.py new file mode 100644 index 0000000..91178e4 --- /dev/null +++ b/plugins/cypher.py @@ -0,0 +1,78 @@ +''' +Plugin which (de)cyphers a string + +Doesn't cypher non-alphanumeric strings yet. + +by instanceoftom +''' + +from util import hook +chars="abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ " +len_chars = len(chars) + +@hook.command +def cypher(inp): + ".cypher -- cyphers a string with the password" + + passwd = inp.split(" ")[0] + len_passwd = len(passwd) + inp = " ".join(inp.split(" ")[1:]) + + out ="" + passwd_index=0 + for character in inp: + try: + chr_index = chars.index(character) + passwd_chr_index = chars.index(passwd[passwd_index]) + + out_chr_index = (chr_index + passwd_chr_index) % len_chars + out_chr = chars[out_chr_index] + + out += out_chr + + passwd_index = ( passwd_index + 1) % len_passwd + except ValueError: + out += character + continue + + return out + +@hook.command +def decypher(inp): + ".decypher -- decyphers a string with the password" + + passwd = inp.split(" ")[0] + len_passwd = len(passwd) + inp = " ".join(inp.split(" ")[1:]) + + + passwd_index=0 + #I am lazy and I could do the math to get the passwd_index + #for this inp, but meh thats for a later day so lets loop. + for character in inp: + try: + chr_index = chars.index(character) + passwd_index = ( passwd_index + 1) % len_passwd + except ValueError: + continue + + passwd_index = passwd_index-1 + reversed_message = inp[::-1] + + out ="" + for character in reversed_message: + try: + chr_index = chars.index(character) + passwd_chr_index = chars.index(passwd[passwd_index]) + + out_chr_index = (chr_index - passwd_chr_index) % len_chars + out_chr = chars[out_chr_index] + + out += out_chr + + passwd_index = ( passwd_index - 1) % len_passwd + except ValueError: + out += character + continue + + return out[::-1] \ No newline at end of file diff --git a/plugins/location.py b/plugins/location.py deleted file mode 100644 index 83f6af7..0000000 --- a/plugins/location.py +++ /dev/null @@ -1,38 +0,0 @@ -from util import hook - -def find_location(ip, api): - import string - import urllib - response = urllib.urlopen("http://api.ipinfodb.com/v3/ip-city/?key="+api+"&ip="+ip).read() - response = response.split(";") - give = {} - give["country"] = response[4].title() - give["country_short"] = response[3].upper() - give["state"] = response[5].title() - give["city"] = response[6].title() - give["timezone"] = response[10].title() - return give - -def timezone(ip): - time = find_location(ip)["timezone"] - time = time.replace(":",".") - time = time.replace(".00","") - return int(time) - -@hook.command -def locations(inp, say = None, me = None, bot = None): - ".location - Performs a GeoIP check on the ip given." - api = bot.config['api_keys']['geoip'] - if api == "": - return "No API key" - give = find_location(inp, api) - if give["country"] not in [""," ","-"," - "]: - if give["state"] == give["city"]: - localstring = give["city"] - else: - localstring = give["city"] + ", " + give["state"] - say("That IP comes from " + give["country"] + " (" + give["country_short"] + ")") - say("I think it's in " + localstring + " with a timezone of " + give["timezone"] + "GMT") - else: - say("Either that wasn't an IP or I cannot locate it in my database. :(") - return