Skip to content

Instantly share code, notes, and snippets.

@MarieKirya95
Last active August 29, 2015 13:57
Show Gist options
  • Save MarieKirya95/9819677 to your computer and use it in GitHub Desktop.
Save MarieKirya95/9819677 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
###################################
# Run Script in Debug mode?
debug = True
# Set it to false if you don't nee it!
###################################
# Import some necessary libraries.
import socket
import time
import platform
import getpass
####################################
# IRC Interface: #
# This is the primary mode of #
# communication with Aigis #
####################################
NSPass = getpass.getpass("NickServ Pass: ")
ChanPass = getpass.getpass("Chan Pass: ")
class ircInterface:
# Some basic variables used to configure the bot
server = "irc.rizon.net" # Server
channelsToJoin = ["#kawayui", "#nyaa-lewd"]
channelsToJoin_pass = [ChanPass, ""]
botnick = "Aigis" # Your bots nick
nickServPass = NSPass
owner = "Mio-chan"
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connected = True
connectedChannels = []
def __init__(self, inServer = server, inNick = botnick, nsIn = nickServPass):
self.server = inServer
self.botnick = inNick
self.nickServPass = nsIn
self.ircsock.connect((self.server, 6667)) # Here we connect to the server using the port 6667
self.ircsock.send("USER "+ self.botnick +" "+ self.botnick +" "+ self.botnick +" :Aigis\n") # user authentication
self.ircsock.send("NICK "+ self.botnick +"\n") # here we actually assign the nick to the bot
self.authNickServ()
while self.connected:
ircmsg = self.ircsock.recv(2048) # receive data from the server
ircmsg = ircmsg.strip('\n\r') # removing any unnecessary linebreaks.
###### Parse like no tomorrow ##########
name = ircmsg[ircmsg.find(":")+1:ircmsg.find("!")]
message = ircmsg[ircmsg.find(":",2)+1:]
if ircmsg.find("PRIVMSG") != -1:
origin = ircmsg[ircmsg.find("PRIVMSG",2)+8:ircmsg.find(":",2)]
else:
origin = "Server Msg"
####### Print some readable data ############
if debug:
print(ircmsg)
print("Name: "+name+"; Message: " + message +"; Origin: " + origin)
else:
print("<"+name+"> " + message)
###### Events #########
if ircmsg.find("Password accepted - you are now recognized") != -1:
self.sendmsg(self.owner,"Aigis Console Initiated.")
self.sendmsg(self.owner, self.owner+"@"+self.botnick+":/")
self.joinDefaultChannels() # Join the channel using the functions we previously defined
if ircmsg.find(":Hello "+ self.botnick) != -1: # If we can find "Hello Mybot" it will call the function hello()
self.sendmsg(origin, "Hello " + name +"!")
if message.find(self.botnick + " help") != -1:
self.sendmsg(origin, "Engaging battle mode! Where are the shadows?!")
if ircmsg.find("PING :") != -1: # if the server pings us then we've got to respond!
self.ping()
if name == self.owner and message.find("\x01ACTION puts " + self.botnick + " into hibernate") != -1:
self.quitIRC()
if ircmsg.find("\x01ACTION hugs " + self.botnick) != -1:
self.sendaction(origin, "hugs " + name + "~")
if ircmsg.find("\x01ACTION kisses " + self.botnick) != -1 and name=="Pandaborg":
self.sendaction(origin, "kisses " + name + ", holds her hand, and sits down with her~")
if ircmsg.find("\x01ACTION has sex with " + self.botnick) != -1 and name=="that4chanwolf":
self.sendaction(origin, self.owner + "! " + name + " is trying to sexually harrass me. Help~")
if ircmsg.find("\x01ACTION kisses " + self.botnick) != -1 and name!="Pandaborg":
self.sendaction(origin, "waits until " + name + " stops kissing.")
time.sleep(5)
self.sendmsg(origin, "I-I'm sorry, b-but I already have someone...")
self.sendaction(origin, "blushes and shy's away")
if ircmsg.find("JOIN") != -1 and name != "Aigis":
self.sendaction(message, "hugs " + name + "~")
if name == self.owner and origin == self.botnick + " ":
self.processConsoleReq(message)
## CTCP
if message.find("VERSION") !=-1:
self.respondVersion(name)
def respondVersion(self, name):
if debug:
print("replying to " + name + " with VERSION with:")
print("NOTICE "+ name+ " :" + "Aigis 7th Gen. Anti-Shadow Surpression Weapon. Running " + platform.uname()[0] + " on " + platform.uname()[5])
self.ircsock.send("NOTICE "+ name+ " :" + "Aigis 7th Gen. Anti-Shadow Surpression Weapon. Running " + platform.uname()[0] + " on " + platform.uname()[5]+"\n")
def ping(self): # Reply to Server PINGs
self.ircsock.send("PONG :pingis\n")
def processConsoleReq(self, command): ## TODO: SENDACTION"
responce = "Nothing preformed. Check your syntax and try again. If you forgot what you programmed type 'HELP'."
action = command.split()
if debug:
print(action)
if action[0].find("HELP") != -1:
responce = "Available Commands: HELP, JOINCHAN, LEAVECHAN, QUIT, SENDMSG, SENDALL"
elif action[0].find("JOINCHAN") != -1:
if len(action) > 2:
self.joinchan(action[1],action[2])
responce = "Joining requested channel!"
elif len(action) > 1:
self.joinchan(action[1])
responce = "Joining requested channel!"
else:
responce = "Not enough arguments. JOINCHAN #[channel] ([password])"
elif action[0].find("LEAVECHAN") != -1:
if len(action) > 1:
self.leavechan(action[1])
responce = "Left requested channel!"
else:
responce = "Not enough arguments. LEAVECHAN #[channel]"
elif action[0].find("QUIT") != -1:
self.quitIRC()
elif action[0].find("SENDMSG") != -1:
if len(action) > 2:
self.sendmsg(action[1],self.joinArgForSend(action[2:]))
responce = "Message sent!"
else:
responce = "Not enough arguments. SENDMSG [target] [message]"
elif action[0].find("SENDALL") != -1:
if len(action) > 1:
self.sendmsgall(self.joinArgForSend(action[1:]))
responce = "Sent message to all connected channels!"
else:
responce = "Not enough arguments. SENDALL [message]"
elif action[0].find("SENDACTION") != -1:
if len(action) > 2:
self.sendaction(action[1],self.joinArgForSend(action[2:]))
responce = "Sent action to channel!"
else:
responce = "Not enough arguments. SENDACTION [target] [message]"
self.sendmsg(self.owner, responce)
def sendmsgall(self, msg):
for joinedChan in self.connectedChannels:
self.sendmsg(joinedChan, msg)
def sendmsg(self, chan , msg): # This is the send message function, it simply sends messages to the channel.
self.ircsock.send("PRIVMSG "+ chan +" :"+ msg +"\n")
def sendaction(self, chan, action):
self.sendmsg(chan, "\x01ACTION " + action + "\x01")
def joinArgForSend(self, messageArray):
return " ".join(messageArray);
def quitIRC(self):
self.sendmsgall("Good night! I'll see you soon~")
self.ircsock.send("QUIT :Time to kick shadows and chew bubble gum.\n")
self.connected = False
self.ircsock = None
self = None
def authNickServ(self):
self.ircsock.send("PRIVMSG NickServ :"+ "identify " + self.nickServPass +"\n")
def joinchan(self, chan, cpass = ""): # This function is used to join channels.
self.connectedChannels.append(chan)
self.ircsock.send("JOIN "+ chan + " " + cpass +"\n")
def leavechan(self, chan): # This function is used to join channels.
self.connectedChannels.remove(chan)
self.ircsock.send("PART "+ chan +"\n")
def joinDefaultChannels(self):
for (i, tojoin) in enumerate(self.channelsToJoin):
self.joinchan(tojoin,self.channelsToJoin_pass[i])
####################################
# BattleUser: #
# This class creates a general use #
# user with RPG stats, inventory, #
# etc. Made to be extendable #
####################################
class BattleUser:
#Base Stats
MaxHP = 50 # Amount of hitpoints the user has.
Magic = 2 # Base stat for magic attack and defence. If user has 2, then
Endurance = 2 # Physical Defence
Strength = 2 # Physical Attack
Agility = 2 # Turn Speed
Luck = 2 # Crit Rate
#EXP
Level = 1
Experience = 0
#Movesets
Moveset = []
#Passive Skill
PassiveSkill = ""
#Personal
Name = "Unknown Challenger"
# Avatar = "image.png" #maybe later...
Title = "Beginner"
TotalRupees = 0
#Current
CurHP = 50
CurMagic = 2
CurEndurance = 2
CurStrength = 2
CurAgility = 2
CurLuck = 2
LastActive = 0
willToFight = True
#Equipment
def __init__(self, nickToLoad):
self.loadData(nickToLoad)
def loadData(self, nickToLoad):
print("loading data... or not");
#IDEA
#Check Users/nick.py for the nick
#there?
#load the file and set vars
#not there?
#make a new user file and save it
def saveData(self):
print("Saving... Please do not turn off the power...")
#IDEA
#Save as Users/nick.py
#Save your data in such a way that you are generating code that you will run in the future.
#This may be exploitable if you don't look for ESCAPE CARACHTERS. Check for them you lazy fag.
def healChar(self, measurement, magnitude):
if (measurement == 1):
if (self.MaxHP-self.CurHP < magnitude):
self.CurHP = self.MaxHP
else:
self.CurHP += magnitude
else:
self.healChar(1,((magnitude/100)*self.MaxHP))
def damageChar(self, measurement, magnitude):
if (measurement == 1):
if (self.CurHP - magnitude <= 0):
self.CurHP = 0
self.willToFight = False
else:
self.CurHP -= magnitude
else:
self.damageChar(1,((magnitude/100)*self.MaxHP))
def clearBuffs():
self.CurMagic = self.Magic
self.CurEndurance = self.Endurance
self.CurStrength = self.Strength
self.CurAgility = self.Agility
self.CurLuck = self.Luck
####################################
# BattleMove: #
# This is a move object, it tells #
# the engine what a skill would do #
####################################
class BattleMove:
#Effect (none = 0, damage = 1, buff = 2, heal = 3, special = 4)
effect = 0
#measurement (points = 1, precent = 2)
measurement = 0
#magnitude (points measured in raw, precent measured from 0-100)
magnitude = 0
#name
name = "Unknown Move"
def __init__(self, moveToLoad):
self.loadMove(moveToLoad)
def loadMove(self, move):
#Find move in ./moves/move_name.py
#Doesn't exist?
#error out
#load vars
print("loading move")
def useMove(self, target):
#Placeholder for basic effects
print("using move")
####################################
# BattleItem: #
# This is a item object, it tells #
# the engine what an item would do #
####################################
class BattleItem:
#type (1= equipable, 2=perishable)
itemType = 0
#equippable location (0 = non-equip, 1 = torso, 2 = legs, 3 = weapon, 4 = extra accessory)
equippableLoc = 0
#buffs (if equipped, raises max stats. if consumed, raises temp stats)
HP = 0
Magic = 0
Endurance = 0
Strength = 0
Agility = 0
Luck = 0
####################################
# Aigis: #
# The bot's starting point. #
####################################
class Aigis:
def __init__(self):
print("Aigis IRC RPG System starting...")
self.main()
def main(self):
RizonInterface = ircInterface()
LocalAigis = Aigis() # Make the 7th Generation Anti-Shadow Surpression Weapons, Aigis.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment