make it spicy
This commit is contained in:
parent
577a7b58ce
commit
f52623ecbe
20
README.md
20
README.md
@ -1,18 +1,20 @@
|
|||||||
# IRC_Drug_Dealer
|
# IRC Spice Helper
|
||||||
IRC Drug Dealing Bot
|
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ import socket
|
|||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
import shelve
|
import shelve
|
||||||
import _pickle
|
import time
|
||||||
|
|
||||||
#dealer class
|
#dealer class
|
||||||
class Dealer:
|
class Dealer:
|
||||||
@ -26,110 +26,114 @@ class Dealer:
|
|||||||
#create unique save files for everyone
|
#create unique save files for everyone
|
||||||
f = shelve.open("{}.dat".format(self.name), flag="c", writeback=True)
|
f = shelve.open("{}.dat".format(self.name), flag="c", writeback=True)
|
||||||
f["name"] = self.name
|
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:
|
if not "inventory" in f:
|
||||||
f["inventory"] = {}
|
f["inventory"] = {}
|
||||||
f["inventory"]["money"] = 500
|
f["inventory"]["twigs"] = 500
|
||||||
f["inventory"]["meth"] = 10
|
f["inventory"]["wasabi"] = 10
|
||||||
f["inventory"]["heroin"] = 10
|
f["inventory"]["onions"] = 10
|
||||||
f["inventory"]["cocaine"] = 10
|
f["inventory"]["garlic"] = 10
|
||||||
f.sync()
|
f.sync()
|
||||||
self.inventory = {}
|
self.inventory = {}
|
||||||
self.inventory["money"] = 500
|
self.inventory["twigs"] = 500
|
||||||
self.inventory["meth"] = 10
|
self.inventory["wasabi"] = 10
|
||||||
self.inventory["heroin"] = 10
|
self.inventory["onions"] = 10
|
||||||
self.inventory["cocaine"] = 10
|
self.inventory["garlic"] = 10
|
||||||
else:
|
else:
|
||||||
self.inventory = f["inventory"]
|
self.inventory = f["inventory"]
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
#sell function, writes to save file
|
#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)
|
f = shelve.open("{}.dat".format(self.name), flag="c", writeback=True)
|
||||||
if (int(f["inventory"][drug] >= 1)):
|
if (int(f["inventory"][spice] >= 1)):
|
||||||
f["inventory"][drug] -= int(amount)
|
f["inventory"][spice] -= int(amount)
|
||||||
f["inventory"]["money"] += (int(amount) * int(price))
|
f["inventory"]["twigs"] += (int(amount) * int(price))
|
||||||
drug_respond = str(drug)
|
spice_respond = str(spice)
|
||||||
drug_respond_amount = str(f["inventory"][drug])
|
spice_respond_amount = str(f["inventory"][spice])
|
||||||
drug_respond_cash = str(f["inventory"]["money"])
|
spice_respond_cash = str(f["inventory"]["twigs"])
|
||||||
#responds to channel, then syncs
|
#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.sync()
|
||||||
f.close()
|
f.close()
|
||||||
else:
|
else:
|
||||||
sendmsg(channel, "Not enough drugs")
|
sendmsg(channel, "Sorry, missing some spices.")
|
||||||
#buy function
|
#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)
|
f = shelve.open("{}.dat".format(self.name), flag="c", writeback=True)
|
||||||
if (int((f["inventory"]["money"])) >= (int(amount) * int(price))):
|
if (int((f["inventory"]["twigs"])) >= (int(amount) * int(price))):
|
||||||
f["inventory"][drug] += int(amount)
|
f["inventory"][spice] += int(amount)
|
||||||
f["inventory"]["money"] -= (int(amount) * int(price))
|
f["inventory"]["twigs"] -= (int(amount) * int(price))
|
||||||
drug_respond = str(drug)
|
spice_respond = str(spice)
|
||||||
drug_respond_amount = str(f["inventory"][drug])
|
spice_respond_amount = str(f["inventory"][spice])
|
||||||
drug_respond_cash = str(f["inventory"]["money"])
|
spice_respond_cash = str(f["inventory"]["twigs"])
|
||||||
#responds to channel, then syncs
|
#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.sync()
|
||||||
f.close()
|
f.close()
|
||||||
else:
|
else:
|
||||||
sendmsg(channel, "Not enough cash")
|
sendmsg(channel, "Dude, you need more twigs!")
|
||||||
|
|
||||||
|
|
||||||
#allows user to check amounts of resources
|
#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)
|
f = shelve.open("{}.dat".format(self.name), flag="c", writeback=True)
|
||||||
if drug is "heroin":
|
if spice is "onions":
|
||||||
return(f["inventory"]['heroin'])
|
return(f["inventory"]['onions'])
|
||||||
f.sync()
|
f.sync()
|
||||||
f.close()
|
f.close()
|
||||||
if drug is "cocaine":
|
if spice is "garlic":
|
||||||
return(self.inventory['cocaine'])
|
return(self.inventory['garlic'])
|
||||||
f.sync()
|
f.sync()
|
||||||
f.close()
|
f.close()
|
||||||
if drug is "meth":
|
if spice is "wasabi":
|
||||||
return(self.inventory['meth'])
|
return(self.inventory['wasabi'])
|
||||||
f.sync()
|
f.sync()
|
||||||
f.close()
|
f.close()
|
||||||
if drug is "money":
|
if spice is "twigs":
|
||||||
return(self.inventory['money'])
|
return(self.inventory['twigs'])
|
||||||
f.sync()
|
f.sync()
|
||||||
f.close()
|
f.close()
|
||||||
else:
|
else:
|
||||||
return("Drug not specified")
|
return("What do you want?")
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
#******** IRC SHIT *********
|
#******** IRC SHIT *********
|
||||||
|
|
||||||
server = "irc.freenode.net"
|
server = "km3jy7nrj3e2wiju.onion"
|
||||||
channel = "#lainchan"
|
channel = "#anarchyplanet"
|
||||||
botnick = "drug-bot"
|
botuser = "herbs"
|
||||||
|
botnick = "spicy"
|
||||||
password = ""
|
password = ""
|
||||||
#all bytes must be converted to UTF-8
|
|
||||||
def joinchan(chan): #channel join function
|
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
|
#creates sockets, assigns nicks and usernames, and identifies
|
||||||
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
ircsock.connect((server, 6667))
|
ircsock.connect((server, 6667))
|
||||||
ircsock.send(bytes("USER "+ botnick +" "+ botnick +" "+ botnick +" :connected\n", "UTF-8"))
|
ircsock.send(bytes("USER "+ botuser +" "+ botuser +" "+ botuser +" :connected\n"))
|
||||||
ircsock.send(bytes("NICK "+ botnick +"\n", "UTF-8"))
|
ircsock.send(bytes("NICK "+ botnick +"\n"))
|
||||||
ircsock.send(bytes("NICKSERV :IDENTIFY %s\r\n" % password, "UTF-8"))
|
#ircsock.send(bytes("NICKSERV :IDENTIFY %s\r\n" % password))
|
||||||
#sleep for 2 to give server time to process
|
#sleep some to give server time to process
|
||||||
time.sleep(2)
|
time.sleep(10)
|
||||||
joinchan(channel) #joins channel
|
joinchan(channel) #joins channel
|
||||||
readbuffer = ""
|
readbuffer = ""
|
||||||
#main loop
|
#main loop
|
||||||
while 1:
|
while 1:
|
||||||
#assigns random drug prices
|
#assigns random spice prices
|
||||||
drug_price = random.randrange(5,15,1)
|
spice_price = random.randrange(5,15,1)
|
||||||
#function to send messages to IRC channel
|
#function to send messages to IRC channel
|
||||||
def sendmsg(chan , msg):
|
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
|
#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
|
#splits into lines then prints out in shell
|
||||||
temp = str.split(readbuffer, "\n")
|
temp = str.split(readbuffer, "\n")
|
||||||
|
if readbuffer is None:
|
||||||
|
time.sleep(1)
|
||||||
|
continue
|
||||||
print(readbuffer)
|
print(readbuffer)
|
||||||
readbuffer=temp.pop( )
|
readbuffer=temp.pop( )
|
||||||
|
|
||||||
@ -139,9 +143,9 @@ while 1:
|
|||||||
try:
|
try:
|
||||||
#respond to pings
|
#respond to pings
|
||||||
if(line[0] == "PING"):
|
if(line[0] == "PING"):
|
||||||
ircsock.send(bytes("QUOTE :PONG %s\r\n" % line[1], "UTF-8"))
|
ircsock.send(bytes("QUOTE :PONG %s\r\n" % line[1]))
|
||||||
#if it finds .sell, it calls the function from the drug user class
|
#if it finds .sell, it calls the function from the spice user class
|
||||||
if(line[3] == ":.sell"):
|
if(line[3] == ":.help"):
|
||||||
#get name of person who called command
|
#get name of person who called command
|
||||||
sender = ""
|
sender = ""
|
||||||
for char in line[0]:
|
for char in line[0]:
|
||||||
@ -151,13 +155,24 @@ while 1:
|
|||||||
sender += char
|
sender += char
|
||||||
#assigns player a save file
|
#assigns player a save file
|
||||||
current_player = Dealer(sender)
|
current_player = Dealer(sender)
|
||||||
#drug wanted
|
sendmsg(channel, ("Check your stuff with .count. Use .get and .drop to juggle them around."))
|
||||||
drug_query = line[5]
|
if(line[3] == ":.drop"):
|
||||||
#amount of drug
|
#get name of person who called command
|
||||||
drug_amount = line[4]
|
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
|
#calls the sell function from dealer class, passing in data collected above
|
||||||
current_player.sell(drug_query, drug_price, drug_amount)
|
current_player.sell(spice_query, spice_price, spice_amount)
|
||||||
if(line[3] == ":.buy"):
|
if(line[3] == ":.get"):
|
||||||
#get name of person who called command
|
#get name of person who called command
|
||||||
sender = ""
|
sender = ""
|
||||||
for char in line[0]:
|
for char in line[0]:
|
||||||
@ -167,13 +182,13 @@ while 1:
|
|||||||
sender += char
|
sender += char
|
||||||
#assigns player a save file
|
#assigns player a save file
|
||||||
current_player = Dealer(sender)
|
current_player = Dealer(sender)
|
||||||
#type of drug
|
#type of spice
|
||||||
drug_query = line[5]
|
spice_query = line[5]
|
||||||
#amount of drug
|
#amount of spice
|
||||||
drug_amount = line[4]
|
spice_amount = line[4]
|
||||||
#calls the buy function from dealer class, passing in data collected above
|
#calls the buy function from dealer class, passing in data collected above
|
||||||
current_player.buy(drug_query, drug_price, drug_amount)
|
current_player.buy(spice_query, spice_price, spice_amount)
|
||||||
if(line[3] == ":.check"):
|
if(line[3] == ":.count"):
|
||||||
sender = ""
|
sender = ""
|
||||||
for char in line[0]:
|
for char in line[0]:
|
||||||
if(char == "!"):
|
if(char == "!"):
|
||||||
@ -185,16 +200,16 @@ while 1:
|
|||||||
requested_item = line[4]
|
requested_item = line[4]
|
||||||
#returns the value of the requested item
|
#returns the value of the requested item
|
||||||
if requested_item:
|
if requested_item:
|
||||||
if(requested_item == 'heroin'):
|
if(requested_item == 'onions'):
|
||||||
sendmsg(channel, (sender + ", you have " + str(current_player.check_amount('heroin')) + " heroin left" +"\n"))
|
sendmsg(channel, (sender + ", you have " + str(current_player.check_amount('onions')) + " onions left" +"\n"))
|
||||||
elif(requested_item == 'meth'):
|
elif(requested_item == 'wasabi'):
|
||||||
sendmsg(channel, (sender + ", you have " + str(current_player.check_amount('meth')) + " meth left" +"\n"))
|
sendmsg(channel, (sender + ", you have " + str(current_player.check_amount('wasabi')) + " wasabi left" +"\n"))
|
||||||
elif(requested_item == 'money'):
|
elif(requested_item == 'twigs'):
|
||||||
sendmsg(channel, (sender + ", you have " + str(current_player.check_amount('money')) + " money left" +"\n" ))
|
sendmsg(channel, (sender + ", you have " + str(current_player.check_amount('twigs')) + " twigs left" +"\n" ))
|
||||||
elif(requested_item == 'cocaine'):
|
elif(requested_item == 'garlic'):
|
||||||
sendmsg(channel, (sender + ", you have " + str(current_player.check_amount('cocaine')) + " cocaine left" +"\n"))
|
sendmsg(channel, (sender + ", you have " + str(current_player.check_amount('garlic')) + " garlic left" +"\n"))
|
||||||
else:
|
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:
|
except:
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue
Block a user