diff --git a/README.md b/README.md index 18da7b2..11a9166 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,20 @@ -# IRC_Drug_Dealer -IRC Drug Dealing Bot +# IRC Spice Helper -This bot is an IRC game that allows you to buy and sell drugs, and saves your score. +This is a modified version of the IRC bot game https://github.com/happy-box/IRC_Drug_Dealer -I plan to add more features in the future, but for now, here are the commands: +It allows you to play around with spices and twigs. Have fun! -.buy [amount] [drug] +.drop [amount] [drug] -.sell [amount] [drug] +.get [amount] [drug] -.check [drug OR 'money'] +.count [spice OR 'twigs'] -Currently there are 3 drugs: heroin, meth, and cocaine +Currently there are 3 spices: wasabi, onions, and garlic -All players start out with 10 of each drug, and 500 cash. This can be changed by editing the main .py file. You may also change the bot's nick, target channel/network, and identification settings by scrolling down to the IRC section and changing the variables. I recommend leaving this bot in a seperate directory/folder because the amount of .dat files can get pretty big. +All players start out with 10 of each spice, and 500 twigs. +# Installation and Configuraiton + +This can be changed by editing the main .py file. You may also change the bot's nick, target channel/network, and identification settings by scrolling down to the IRC section and changing the variables. I recommend leaving this bot in a seperate directory/folder because the amount of .dat files can get pretty big. diff --git a/drug_bot.py b/spicy_bot.py similarity index 51% rename from drug_bot.py rename to spicy_bot.py index dc42cf4..08e093f 100644 --- a/drug_bot.py +++ b/spicy_bot.py @@ -16,7 +16,7 @@ import socket import random import time import shelve -import _pickle +import time #dealer class class Dealer: @@ -26,110 +26,114 @@ class Dealer: #create unique save files for everyone f = shelve.open("{}.dat".format(self.name), flag="c", writeback=True) f["name"] = self.name - #assign drugs for first time, or load existing file + #assign spices for first time, or load existing file if not "inventory" in f: f["inventory"] = {} - f["inventory"]["money"] = 500 - f["inventory"]["meth"] = 10 - f["inventory"]["heroin"] = 10 - f["inventory"]["cocaine"] = 10 + f["inventory"]["twigs"] = 500 + f["inventory"]["wasabi"] = 10 + f["inventory"]["onions"] = 10 + f["inventory"]["garlic"] = 10 f.sync() self.inventory = {} - self.inventory["money"] = 500 - self.inventory["meth"] = 10 - self.inventory["heroin"] = 10 - self.inventory["cocaine"] = 10 + self.inventory["twigs"] = 500 + self.inventory["wasabi"] = 10 + self.inventory["onions"] = 10 + self.inventory["garlic"] = 10 else: self.inventory = f["inventory"] f.close() #sell function, writes to save file - def sell(self, drug, price, amount): + def sell(self, spice, price, amount): f = shelve.open("{}.dat".format(self.name), flag="c", writeback=True) - if (int(f["inventory"][drug] >= 1)): - f["inventory"][drug] -= int(amount) - f["inventory"]["money"] += (int(amount) * int(price)) - drug_respond = str(drug) - drug_respond_amount = str(f["inventory"][drug]) - drug_respond_cash = str(f["inventory"]["money"]) + if (int(f["inventory"][spice] >= 1)): + f["inventory"][spice] -= int(amount) + f["inventory"]["twigs"] += (int(amount) * int(price)) + spice_respond = str(spice) + spice_respond_amount = str(f["inventory"][spice]) + spice_respond_cash = str(f["inventory"]["twigs"]) #responds to channel, then syncs - sendmsg(channel, ("You have " + drug_respond_amount + " " + str(drug) + " left, and $" + drug_respond_cash + " left")) + sendmsg(channel, ("You have " + spice_respond_amount + " " + str(spice) + " left, and $" + spice_respond_cash + " left")) f.sync() f.close() else: - sendmsg(channel, "Not enough drugs") + sendmsg(channel, "Sorry, missing some spices.") #buy function - def buy(self, drug, price, amount): + def buy(self, spice, price, amount): f = shelve.open("{}.dat".format(self.name), flag="c", writeback=True) - if (int((f["inventory"]["money"])) >= (int(amount) * int(price))): - f["inventory"][drug] += int(amount) - f["inventory"]["money"] -= (int(amount) * int(price)) - drug_respond = str(drug) - drug_respond_amount = str(f["inventory"][drug]) - drug_respond_cash = str(f["inventory"]["money"]) + if (int((f["inventory"]["twigs"])) >= (int(amount) * int(price))): + f["inventory"][spice] += int(amount) + f["inventory"]["twigs"] -= (int(amount) * int(price)) + spice_respond = str(spice) + spice_respond_amount = str(f["inventory"][spice]) + spice_respond_cash = str(f["inventory"]["twigs"]) #responds to channel, then syncs - sendmsg(channel, ("You have " + drug_respond_amount + " " + str(drug) + " left, and $" + drug_respond_cash + " left")) + sendmsg(channel, ("You have " + spice_respond_amount + " " + str(spice) + " left, and $" + spice_respond_cash + " left")) f.sync() f.close() else: - sendmsg(channel, "Not enough cash") + sendmsg(channel, "Dude, you need more twigs!") #allows user to check amounts of resources - def check_amount(self, drug): + def check_amount(self, spice): f = shelve.open("{}.dat".format(self.name), flag="c", writeback=True) - if drug is "heroin": - return(f["inventory"]['heroin']) + if spice is "onions": + return(f["inventory"]['onions']) f.sync() f.close() - if drug is "cocaine": - return(self.inventory['cocaine']) + if spice is "garlic": + return(self.inventory['garlic']) f.sync() f.close() - if drug is "meth": - return(self.inventory['meth']) + if spice is "wasabi": + return(self.inventory['wasabi']) f.sync() f.close() - if drug is "money": - return(self.inventory['money']) + if spice is "twigs": + return(self.inventory['twigs']) f.sync() f.close() else: - return("Drug not specified") + return("What do you want?") f.close() #******** IRC SHIT ********* -server = "irc.freenode.net" -channel = "#lainchan" -botnick = "drug-bot" +server = "km3jy7nrj3e2wiju.onion" +channel = "#anarchyplanet" +botuser = "herbs" +botnick = "spicy" password = "" -#all bytes must be converted to UTF-8 + def joinchan(chan): #channel join function - ircsock.send(bytes("JOIN "+ chan +"\n", "UTF-8")) + ircsock.send(bytes("JOIN "+ chan +"\n")) #creates sockets, assigns nicks and usernames, and identifies ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ircsock.connect((server, 6667)) -ircsock.send(bytes("USER "+ botnick +" "+ botnick +" "+ botnick +" :connected\n", "UTF-8")) -ircsock.send(bytes("NICK "+ botnick +"\n", "UTF-8")) -ircsock.send(bytes("NICKSERV :IDENTIFY %s\r\n" % password, "UTF-8")) -#sleep for 2 to give server time to process -time.sleep(2) +ircsock.send(bytes("USER "+ botuser +" "+ botuser +" "+ botuser +" :connected\n")) +ircsock.send(bytes("NICK "+ botnick +"\n")) +#ircsock.send(bytes("NICKSERV :IDENTIFY %s\r\n" % password)) +#sleep some to give server time to process +time.sleep(10) joinchan(channel) #joins channel readbuffer = "" #main loop while 1: - #assigns random drug prices - drug_price = random.randrange(5,15,1) + #assigns random spice prices + spice_price = random.randrange(5,15,1) #function to send messages to IRC channel def sendmsg(chan , msg): - ircsock.send(bytes("PRIVMSG "+ chan +" :"+ msg +"\n", "UTF-8")) + ircsock.send(bytes("PRIVMSG "+ chan +" :"+ msg +"\n")) #creates a buffer to process the data - readbuffer = readbuffer+ircsock.recv(1024).decode("UTF-8") + buf = readbuffer+ircsock.recv(1024) #splits into lines then prints out in shell temp = str.split(readbuffer, "\n") + if readbuffer is None: + time.sleep(1) + continue print(readbuffer) readbuffer=temp.pop( ) @@ -139,9 +143,9 @@ while 1: try: #respond to pings if(line[0] == "PING"): - ircsock.send(bytes("QUOTE :PONG %s\r\n" % line[1], "UTF-8")) - #if it finds .sell, it calls the function from the drug user class - if(line[3] == ":.sell"): + ircsock.send(bytes("QUOTE :PONG %s\r\n" % line[1])) + #if it finds .sell, it calls the function from the spice user class + if(line[3] == ":.help"): #get name of person who called command sender = "" for char in line[0]: @@ -151,13 +155,24 @@ while 1: sender += char #assigns player a save file current_player = Dealer(sender) - #drug wanted - drug_query = line[5] - #amount of drug - drug_amount = line[4] + sendmsg(channel, ("Check your stuff with .count. Use .get and .drop to juggle them around.")) + if(line[3] == ":.drop"): + #get name of person who called command + sender = "" + for char in line[0]: + if(char == "!"): + break + if(char != ":"): + sender += char + #assigns player a save file + current_player = Dealer(sender) + #spice wanted + spice_query = line[5] + #amount of spice + spice_amount = line[4] #calls the sell function from dealer class, passing in data collected above - current_player.sell(drug_query, drug_price, drug_amount) - if(line[3] == ":.buy"): + current_player.sell(spice_query, spice_price, spice_amount) + if(line[3] == ":.get"): #get name of person who called command sender = "" for char in line[0]: @@ -167,13 +182,13 @@ while 1: sender += char #assigns player a save file current_player = Dealer(sender) - #type of drug - drug_query = line[5] - #amount of drug - drug_amount = line[4] + #type of spice + spice_query = line[5] + #amount of spice + spice_amount = line[4] #calls the buy function from dealer class, passing in data collected above - current_player.buy(drug_query, drug_price, drug_amount) - if(line[3] == ":.check"): + current_player.buy(spice_query, spice_price, spice_amount) + if(line[3] == ":.count"): sender = "" for char in line[0]: if(char == "!"): @@ -185,16 +200,16 @@ while 1: requested_item = line[4] #returns the value of the requested item if requested_item: - if(requested_item == 'heroin'): - sendmsg(channel, (sender + ", you have " + str(current_player.check_amount('heroin')) + " heroin left" +"\n")) - elif(requested_item == 'meth'): - sendmsg(channel, (sender + ", you have " + str(current_player.check_amount('meth')) + " meth left" +"\n")) - elif(requested_item == 'money'): - sendmsg(channel, (sender + ", you have " + str(current_player.check_amount('money')) + " money left" +"\n" )) - elif(requested_item == 'cocaine'): - sendmsg(channel, (sender + ", you have " + str(current_player.check_amount('cocaine')) + " cocaine left" +"\n")) + if(requested_item == 'onions'): + sendmsg(channel, (sender + ", you have " + str(current_player.check_amount('onions')) + " onions left" +"\n")) + elif(requested_item == 'wasabi'): + sendmsg(channel, (sender + ", you have " + str(current_player.check_amount('wasabi')) + " wasabi left" +"\n")) + elif(requested_item == 'twigs'): + sendmsg(channel, (sender + ", you have " + str(current_player.check_amount('twigs')) + " twigs left" +"\n" )) + elif(requested_item == 'garlic'): + sendmsg(channel, (sender + ", you have " + str(current_player.check_amount('garlic')) + " garlic left" +"\n")) else: - sendmsg(channel, ("Invalid option. Options for .check are heroin, meth, cocaine, or money")) + sendmsg(channel, ("Ey, use .check with onions, wasabi, garlic, or twigs")) except: continue