Update FightBot.py

This commit is contained in:
therealvorteckz 2023-10-11 16:14:57 -07:00
parent 8bc469a5d5
commit 173aeac97f

View File

@ -177,7 +177,12 @@ async def heal(name):
if havebandages == None: if havebandages == None:
await bot.sendmsg(config.irc.channel, f'[You do not have any bandages... !buy bandages <amount number>]') await bot.sendmsg(config.irc.channel, f'[You do not have any bandages... !buy bandages <amount number>]')
return return
c.execute(f'SELECT * FROM items WHERE name = (:name)', {'name': name})
bandaids = c.fetchall()
for bandages in bandaids:
if bandages[1] <= 0:
await bot.sendmsg(config.irc.channel, f'[You do not have any bandages... !buy bandages <amount number>]')
return
maxhealth = userinfo[7] maxhealth = userinfo[7]
if health == maxhealth: if health == maxhealth:
await bot.sendmsg(config.irc.channel, f'[You already at FULL HEALTH]') await bot.sendmsg(config.irc.channel, f'[You already at FULL HEALTH]')
@ -423,6 +428,12 @@ async def removeuser(nick):
name = nick name = nick
c.execute('''DELETE FROM users WHERE name=?''',(name,)) c.execute('''DELETE FROM users WHERE name=?''',(name,))
conn.commit() conn.commit()
c.execute('''DELETE FROM items WHERE name=?''',(name,))
conn.commit()
c.execute('''DELETE FROM weapons WHERE name=?''',(name,))
conn.commit()
c.execute('''DELETE FROM stats WHERE name=?''',(name,))
conn.commit()
logging.debug(f'Removed user {nick}') logging.debug(f'Removed user {nick}')
async def createuser(nick): async def createuser(nick):
@ -683,6 +694,23 @@ async def getmoney(nick):
moneyamount = money[6] moneyamount = money[6]
writemoney = f'{moneyamount:,}' writemoney = f'{moneyamount:,}'
await bot.sendmsg(config.irc.channel, f'[Bank Balance: ${color(writemoney, light_blue)}]') await bot.sendmsg(config.irc.channel, f'[Bank Balance: ${color(writemoney, light_blue)}]')
async def getbandages(nick):
name = nick
c.execute(f'SELECT rowid FROM items WHERE name=(:name)', {'name': nick})
data=c.fetchone()
if data is None:
bandages = 0
c.execute(f'INSERT OR REPLACE INTO items VALUES (:name, :bandages)', {'name': name, 'bandages': bandages})
conn.commit()
c.execute(f"SELECT * FROM items WHERE name=(:name)", {'name': nick})
bandages = c.fetchall()
for bandage in bandages:
bandageamount = bandage[1]
if bandageamount == None:
logging.debug('test')
bandageamount = 0
writebandageamount = f'{bandageamount:,}'
await bot.sendmsg(config.irc.channel, f'[Bandages: {color(writebandageamount, red)}]')
async def ammo(nick): async def ammo(nick):
c.execute(f'SELECT rowid FROM users WHERE name=(:name)', {'name': nick}) c.execute(f'SELECT rowid FROM users WHERE name=(:name)', {'name': nick})
@ -759,7 +787,7 @@ class Bot():
time.sleep(config.throttle.msg) time.sleep(config.throttle.msg)
except: except:
await bot.sendmsg(config.irc.channel, "Slow Down Nerd!") await bot.sendmsg(config.irc.channel, "Slow down homie!!")
async def connect(self): async def connect(self):
'''Connect to the IRC server.''' '''Connect to the IRC server.'''
@ -814,7 +842,7 @@ class Bot():
await self.raw(f'JOIN {chan}') await self.raw(f'JOIN {chan}')
elif args[1] == 'PRIVMSG': elif args[1] == 'PRIVMSG':
ident = args[0][1:] ident = args[0][1:]
nick = args[0].split('!')[0][1:] nick = args[0].split('!')[0][1:].lower()
target = args[2] target = args[2]
msg = ' '.join(args[3:])[1:] msg = ' '.join(args[3:])[1:]
arguments = msg.split() arguments = msg.split()
@ -845,7 +873,6 @@ class Bot():
await buyweapon(nick) await buyweapon(nick)
elif arguments[1] == 'ammo': elif arguments[1] == 'ammo':
await buyammo(nick) await buyammo(nick)
elif arguments[1] == 'bandages': elif arguments[1] == 'bandages':
if len(arguments) <= 2 or int(arguments[2]) == 0: if len(arguments) <= 2 or int(arguments[2]) == 0:
await bot.sendmsg(config.irc.channel, '[You must specify amount of bandages (greater than 0) to purchase]') await bot.sendmsg(config.irc.channel, '[You must specify amount of bandages (greater than 0) to purchase]')
@ -853,7 +880,7 @@ class Bot():
await buybandages(nick, int(arguments[2])) await buybandages(nick, int(arguments[2]))
if arguments[0] == '!shoot': if arguments[0] == '!shoot':
await shoot(arguments[1], nick) await shoot(arguments[1].lower(), nick)
if arguments[0] == '!reload': if arguments[0] == '!reload':
await reload(nick) await reload(nick)
if arguments[0] == '!ammo': if arguments[0] == '!ammo':
@ -873,6 +900,7 @@ class Bot():
await bot.sendmsg(config.irc.channel, '[!buy <item> [weapon, ammo, bandages <amount>]') await bot.sendmsg(config.irc.channel, '[!buy <item> [weapon, ammo, bandages <amount>]')
await bot.sendmsg(config.irc.channel, '[!reload - Reloads Weapon]') await bot.sendmsg(config.irc.channel, '[!reload - Reloads Weapon]')
await bot.sendmsg(config.irc.channel, '[!ammo - Show Ammunition Amounts]') await bot.sendmsg(config.irc.channel, '[!ammo - Show Ammunition Amounts]')
await bot.sendmsg(config.irc.channel, '[!bandages - Shows Bandage Amounts]')
await bot.sendmsg(config.irc.channel, '[!revive - Brings you back to health if dead]') await bot.sendmsg(config.irc.channel, '[!revive - Brings you back to health if dead]')
await bot.sendmsg(config.irc.channel, '[!heal - Use bandages to regain health]') await bot.sendmsg(config.irc.channel, '[!heal - Use bandages to regain health]')
await bot.sendmsg(config.irc.channel, ' ') await bot.sendmsg(config.irc.channel, ' ')
@ -883,25 +911,29 @@ class Bot():
await bot.sendmsg(config.irc.channel, '[!removeweapon <user> - Remove user weapon]') await bot.sendmsg(config.irc.channel, '[!removeweapon <user> - Remove user weapon]')
if arguments[0] == '!bank': if arguments[0] == '!bank':
await getmoney(nick) await getmoney(nick)
if arguments[0] == '!bandages':
await getbandages(nick)
if nick in config.irc.admins: if nick in config.irc.admins:
#await self.sendmsg(target, f'{nick} is an ' + color('Admin!', red)) #await self.sendmsg(target, f'{nick} is an ' + color('Admin!', red))
if arguments[0] == '!removeweapon': if arguments[0] == '!removeweapon':
await removeweapon(nick) await removeweapon(nick)
if arguments[0] == '!adduser': if arguments[0] == '!adduser':
name = arguments[1] name = arguments[1].lower()
c.execute(f"SELECT rowid FROM users WHERE name = (:name)", {'name': name}) c.execute(f"SELECT rowid FROM users WHERE name = (:name)", {'name': name})
data=c.fetchone() data=c.fetchone()
if data is None: if data is None:
await bot.sendmsg(config.irc.channel, 'Registering Player: %s'%name) await bot.sendmsg(config.irc.channel, '[Registering Player: %s]'%name)
await createuser(name) await createuser(name)
await profile(name) await profile(name)
else: else:
await bot.sendmsg(config.irc.channel, f'{color("Player already exists!", red)}') await bot.sendmsg(config.irc.channel, f'{color("[Player already exists!]", red)}')
if arguments[0] == '!remove': if arguments[0] == '!remove':
logging.debug('remove user') logging.debug('remove user')
name = arguments[1] name = arguments[1].lower()
c.execute(f"SELECT rowid FROM users WHERE name= (:name)", {'name': name}) c.execute(f"SELECT rowid FROM users WHERE name= (:name)", {'name': name})
data=c.fetchone() data=c.fetchone()
if data != None: if data != None:
@ -911,33 +943,29 @@ class Bot():
await bot.sendmsg(config.irc.channel, f'[User does not exist]') await bot.sendmsg(config.irc.channel, f'[User does not exist]')
if arguments[0] == '!setlevel': if arguments[0] == '!setlevel':
await setlevel(arguments[1], arguments[2]) await setlevel(arguments[1].lower(), arguments[2])
if arguments[0] == '!register': if arguments[0] == '!register':
c.execute(f"SELECT rowid FROM users WHERE name = (:name)", {'name': nick}) c.execute(f"SELECT rowid FROM users WHERE name = (:name)", {'name': nick})
data=c.fetchone() data=c.fetchone()
if data is None: if data is None:
await bot.sendmsg(config.irc.channel, 'Registering Player: %s'%nick) await bot.sendmsg(config.irc.channel, f'[Registering Player: %s]'%nick)
await createuser(nick) await createuser(nick)
await profile(nick) await profile(nick)
else: else:
await bot.sendmsg(config.irc.channel, f'{color("Player already exists!", red)}') await bot.sendmsg(config.irc.channel, f'{color("[Player already exists!]", red)}')
if arguments[0] == '!profile': if arguments[0] == '!profile':
try: try:
await profile(arguments[1]) await profile(arguments[1].lower())
except: except:
await profile(nick) await profile(nick)
if arguments[0] == '!punch': if arguments[0] == '!punch':
await punch(arguments[1].lower(), nick) await punch(arguments[1].lower(), nick)
if msg == '!hello':
await self.sendmsg(target, f'Hello {nick}! Do you like ' + color('colors?', green))
config.throttle.last = time.time() config.throttle.last = time.time()
except Exception as ex: except Exception as ex:
if time.time() - config.throttle.last < config.throttle.cmd: if time.time() - config.throttle.last < config.throttle.cmd:
if not config.throttle.slow: if not config.throttle.slow:
await bot.sendmsg(config.irc.channel, color('Slow down nerd!', red)) await bot.sendmsg(config.irc.channel, color('Slow down homie!', red))
config.throttle.slow = True config.throttle.slow = True
config.throttle.last = time.time() config.throttle.last = time.time()