def setEvent(bot, message): # Parse the input for the event name try: if util.getArg(message.content, 2) is None: yield from bot.send_message( message.channel, ("ℹ Set or update an event.\n" + "`!event set name date time timezone`")) return # Reject eventnames that are longer than 1 word validname = re.match('!event ((set)|(add)) [^ ]* [0-9]', message.content, re.IGNORECASE) if not validname: yield from bot.send_message( message.channel, "❌ The event's name needs to be a single word.") return eventname = util.getArg(message.content, 2) except Exception: return # Parse the input for the datetime eventtime = yield from parseEventTime(message.content) if eventtime is None: yield from bot.send_message( message.channel, ("❌ I didn't understand your date or time, try again.\n" "`!event set name date time timezone`")) return diff = getReadableTimeDiff(eventtime - datetime.now(tz=pytz.timezone('UTC'))) # Add the event if not db.search(where('eventname') == eventname): db.insert({ 'eventname': eventname, 'year': eventtime.year, 'month': eventtime.month, 'day': eventtime.day, 'hour': eventtime.hour, 'minute': eventtime.minute }) yield from bot.send_message( message.channel, ("✅ Event " + eventname + " added! " + diff + "\n" + "See all events with `!event list`.")) else: db.update( { 'year': eventtime.year, 'month': eventtime.month, 'day': eventtime.day, 'hour': eventtime.hour, 'minute': eventtime.minute }, where('eventname') == eventname) yield from bot.send_message( message.channel, ("✅ Event " + eventname + " updated! " + diff + "\n" + "See all events with `!event list`.")) return eventtime
def setnotification(bot, message): global notifications_enabled if util.getArg(message.content, 2) == 'on': notifications_enabled = True yield from bot.send_message(message.channel, "✅ Notifications enabled.") elif util.getArg(message.content, 2) == 'off': notifications_enabled = False yield from bot.send_message(message.channel, "⚠️Notifications disabled.")
def getAndApplyEffect(bot: Bot, message): name = message.author.display_name superUser = util.isSuperUser(message.author) # check cooldown if name not in userStatus: userStatus[name] = [0, None] elif not superUser: cd = getCd(name) if cd > 0: return (yield from bot.send_message(message.channel, name + "'s Wild Magic is on cooldown. Wait " + str(cd) + " more " + pl(cd, 'second') + ".")) userStatus[name][0] = int(time.time()) if str(message.author) == "Poly#0689": return (yield from bot.send_message(message.channel, "(101) Poly is — wait, he's the *DM*! Poly decides" + " what happens!")) roll = randint(0, 100) if superUser: newRoll = util.getArg(message.content, 1) roll = int(newRoll) if newRoll is not None else roll # special cases if roll == 49 or roll == 50: userStatus[name][1] = 'mute' elif roll == 51 or roll == 52: userStatus[name][1] = 'shield' elif roll == 57 or roll == 58: userStatus[name][1] = 'flameBurst' elif roll == 61 or roll == 62: userStatus[name][1] = 'allCaps' elif roll == 71 or roll == 72: userStatus[name][1] = 'resistance' elif roll == 25 or roll == 26: userStatus[name][1] = 'eye' elif roll == 75 or roll == 76: userStatus[name][1] = 'light' elif roll == 79 or roll == 80: userStatus[name][1] = 'butterfly' elif roll == 33 or roll == 34: userStatus[name][1] = 'maxDamageSpell' elif roll == 89 or roll == 90: userStatus[name][1] = 'invisible' elif roll == 91 or roll == 92: userStatus[name][1] = 'revive' elif roll == 93 or roll == 94: userStatus[name][1] = 'big' elif roll == 95 or roll == 96: userStatus[name][1] = 'vulnerable' elif roll == 97 or roll == 98: userStatus[name][1] = 'music' elif roll == 43 or roll == 44: userStatus[name][1] = 'teleport' elif roll == 47 or roll == 48: userStatus[name][1] = 'unicorn' response = '(' + str(roll) + ') ' + effectsTable[roll].replace('{name}', name) return (yield from bot.send_message(message.channel, response))
def startDraw(bot: Bot, message): global currentDraws, currentName if currentDraws > 0: yield from bot.send_message(message.channel, "Wait a moment. " + currentName + " is drawing...") return name = message.author.display_name superUser = util.isSuperUser(message.author) if superUser and util.getArg(message.content, 1) == "reset": yield from bot.send_message(message.channel, "✅ The Deck of Many Things has been reset.") loadEffects() return # check cooldown if name not in userStatus: userStatus[name] = [0, None] elif not superUser: cd = getCd(name) if cd > 0: unit = 'second' if cd > 60: unit = 'minute' cd = int(cd / 60) elif cd > 3600: unit = 'hour' cd = int(cd / 3600) return (yield from bot.send_message(message.channel, name + "'s Deck of Many Things is on cooldown. Wait " + str(cd) + " more " + pl(cd, unit) + ".")) draws = util.getArg(message.content, 1) if not draws: return (yield from bot.send_message(message.channel, "❌ You must state a number of cards to draw. (1-5)")) try: draws = int(draws) except: return (yield from bot.send_message(message.channel, "❌ You must state a number of cards to draw. (1-5)")) if draws < 1 or draws > 5: return (yield from bot.send_message(message.channel, "❌ You must draw between 1 and 5 cards.")) userStatus[name][0] = int(time.time()) currentName = name currentDraws = draws yield from getAndApplyEffect(bot, message)
def removeEvent(bot, message): try: eventname = util.getArg(message.content, 2) if not db.search(where('eventname') == eventname): yield from bot.send_message( message.channel, "⚠ Event " + eventname + " didn't and doesn't exist.") else: db.remove((where('eventname') == eventname)) yield from bot.send_message( message.channel, "✅ Removed the " + eventname + " event.") except Exception: return
def makeSentence(bot, message): try: num = int(util.getArg(message.content, 1)) if num > 10: num = 10 if num < 1: num = 1 except: num = 1 reply = '' for i in range(num): reply += text_model.make_sentence() + ' ' yield from bot.send_message(message.channel, reply)
def courier(message): if str(message.author) == 'stormbird#3705' or str( message.author) == 'stormbird-dev#0449': return if not util.isSuperUser(message.author): return try: channelName = util.getArg(message.content, 1) except: return if not channelName in channel_ids: return (yield from stormbird.send_message(message.channel, "❌ Channel not recognized.")) spChannel = stormbird.get_channel(str(channel_ids[channelName])) yield from stormbird.send_message(spChannel, ' '.join(str.split(message.content)[2:]))
def checkOngoingEffect(bot: Bot, message): name = message.author.display_name superUser = util.isSuperUser(message.author) if superUser: if util.getArg(message.content, 1) == 'clear': # remove all statuses and cooldowns userStatus.clear() return if name not in userStatus or userStatus[name][1] is None: return True cd = getCd(name) if cd <= 0: userStatus[name][1] = None return True effectName = userStatus[name][1] if effectName in effectsEmoji: yield from bot.add_reaction(message, effectsEmoji[effectName]) if effectName == 'mute': yield from bot.send_message(message.channel, "💕 Pink bubbles float out of " + name + "'s mouth! 💕 " + "(" + str(cd) + "s)") try: yield from bot.delete_message(message) except Exception as e: util.log(DEBUG, "Couldn't delete a message.") return False elif effectName == 'maxDamageSpell': userStatus[name][1] = None elif effectName == 'allCaps': if not message.content.isupper(): yield from bot.send_message(message.channel, name + " must shout when they speak! " + "(" + str(cd) + "s)") try: yield from bot.delete_message(message) except Exception as e: util.log(DEBUG, "Couldn't delete a message.") return False return True
def sroll(message): """Rolls d6 dice in N format.""" # Validate syntax try: rollArg = util.getArg(message.content, 1) rolls = int(rollArg) except: return if rolls < 1 or rolls > 30: return result = '' hits = 0 glitches = 0 for r in range(0, rolls): roll = randint(1, 6) if roll >= 5: hits += 1 elif roll == 1: glitches += 1 earr = [ 360257354694000641, 360257354765434892, 360257354853253121, 360257355142922240, 360257355134402560, 360257355138727946 ] emoji = Emoji(id=earr[roll - 1], server=stormbird.get_server(112471696346255360)) result += str(emoji) glitch = '' if glitches > int(rolls / 2): if hits == 0: glitch = ' - ‼️***Critical Glitch*** ‼' else: glitch = ' - ❗ ***Glitch*** ❗' yield from stormbird.send_message( message.channel, '🎲 **' + str(hits) + '** ' + util.pl('hit', hits) + glitch + '\n' + result)
def roll(message): """Rolls a dice in NdN or N format.""" rolls = 1 # default times to roll limit = 100 # default die faces diceArg = util.getArg(message.content, 1) if diceArg is not None: if re.search('^[0-9]+d[0-9]+$', diceArg) is not None: rolls, limit = map(int, diceArg.split('d')) elif re.search('^[0-9]+$', diceArg): limit = int(diceArg) else: return if rolls < 1 or limit < 1: return if rolls > 1000 or limit > 999999999: yield from stormbird.send_message(message.channel, "I'm not doing that much.") return result = ', '.join(str(randint(1, limit)) for r in range(rolls)) yield from stormbird.send_message(message.channel, result)
def list(bot, message): rows = db.all() if not rows: response = 'No events saved yet.' else: userzone = util.getArg(message.content, 2) if userzone is None: userzone = pytz.timezone('US/Eastern') else: # Try to look for P, C, or E try: userzone = TIMEZONES[userzone[0]] except Exception: userzone = pytz.timezone('US/Eastern') nowtime = datetime.now(tz=userzone) response = '🗓 **Events:**' events = [] # Collect the events in a pair of (time, name) for row in rows: eventtime = datetime(row['year'], row['month'], row['day'], row['hour'], row['minute'], tzinfo=pytz.timezone('UTC')) eventtime = eventtime.astimezone(userzone) events.append((eventtime, row['eventname'])) # Now print out the events in sorted order by time events = sorted(events) for eventpair in events: response += ('\n**' + eventpair[1] + ':** ' + eventpair[0].strftime('%b %d (%a), %I:%M%p %Z') + " " + getReadableTimeDiff(eventpair[0] - nowtime)) yield from bot.send_message(message.channel, response)
def updateReaction(bot: Bot, message): try: isRemove = util.getArg(message.content, 1).lower() == 'remove' except Exception: yield from bot.send_message(message.channel, "❌ Check your arguments.") return # Grab and validate username username = '' try: username = util.getArg(message.content, 2) if username is None: yield from bot.send_message(message.channel, "❌ Send me a name, please.") return if not util.isValidUniqueUser(username): yield from bot.send_message( message.channel, "❌ Send me the full name (" + username + "#XXXX), please.") return except ValueError: yield from bot.send_message( message.channel, "❌ The name (" + username + ") is invalid.") username = username.lower() # Grab and validate emoji emoji = util.getArg(message.content, 3) if emoji is None: yield from bot.send_message(message.channel, "❌ Send me an emoji, please.") return # Grab and validate chance chance = 0 if not isRemove: try: chance = int(util.getArg(message.content, 4)) if chance is None: yield from bot.send_message(message.channel, "❌ Send me a chance, please.") return except Exception: yield from bot.send_message(message.channel, "❌ The chance is invalid.") return if chance < 0 or chance > 100: yield from bot.send_message( message.channel, "❌ The chance (" + str(chance) + ") needs to be within 0 and 100.") return if username is None or emoji is None or (chance is None and not isRemove): yield from bot.send_message(message.channel, "❌ One of the args is None!") return if isRemove: db.remove((where('username') == username) & (where('emoji') == emoji)) yield from bot.send_message( message.channel, "✅ Removed the " + emoji + " proc from " + util.getArg(message.content, 2) + ".") else: if not db.search((where('username') == username) & (where('emoji') == emoji)): db.insert({'username': username, 'emoji': emoji, 'chance': chance}) yield from bot.send_message( message.channel, "✅ Gave " + util.getArg(message.content, 2) + " a " + str(chance) + "% chance to proc " + emoji + ".") else: db.update({'chance': chance}, (where('username') == username) & (where('emoji') == emoji)) yield from bot.send_message( message.channel, "✅ Updated " + util.getArg(message.content, 2) + " with a " + str(chance) + "% chance to proc " + emoji + ".") return