botalan

discord bot
git clone git://git.benoneill.xyz/botalan
Log | Files | Refs | README | LICENSE

commit 604a1a23c7be27500a23eb94135d5fa2bdf806a8
Author: Ben O'Neill <ben@benoneill.xyz>
Date:   Tue,  7 Sep 2021 10:48:45 -0400

first commit

Diffstat:
ALICENSE | 21+++++++++++++++++++++
AREADME.md | 27+++++++++++++++++++++++++++
Abotalan.py | 44++++++++++++++++++++++++++++++++++++++++++++
Acmd.py | 28++++++++++++++++++++++++++++
Aconfig.sh | 2++
Astart.sh | 9+++++++++
Astop.sh | 6++++++
Atweet.py | 114+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 251 insertions(+), 0 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Ben O'Neill <ben@benoneill.xyz> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md @@ -0,0 +1,27 @@ +# botalan + +botalan is a Discord bot written in Python. It is very basic, but more +features may be added later. +[Name origin](https://youtu.be/_swLxZu-exU). + +## Commands + +* `!fortune`: print fortune from system `fortune(1)`. +* `!cowsay <msg>`: print given string using system `cowsay(1)`. +* `!cowfortune`: print result of `fortune | cowsay`. +* `!tweet`: print a random Twitter shitpost from a bank. + +## Dependencies + +* tmux +* [discord.py](https://discordpy.readthedocs.io/en/stable/) + +## Usage + +Obtain a bot token, then run `start.sh` and enter the token. To stop, +run `stop.sh`. + +## License + +Copyright (C) 2021 Ben O'Neill <ben@benoneill.xyz>. License: MIT. +See LICENSE for more details. diff --git a/botalan.py b/botalan.py @@ -0,0 +1,44 @@ +import discord +import os +import cmd + +TOKEN = os.getenv("TOKEN") + +client = discord.Client() + +def exec_cmd(msg): + response = '' + msg = msg.strip() + if msg == '!tweet': + response = cmd.tweet() + if msg == '!fortune': + response = cmd.fortune() + if msg.startswith('!cowsay ') and len(msg) > len('!cowsay '): + index = msg.index(' ') + 1 + cowmsg = msg[index:] + response = cmd.cowsay(cowmsg) + if msg == ('!cowfortune'): + response = cmd.cowfortune() + + return response + +@client.event +async def on_ready(): + print('bot alan has entered the discord realm') + +@client.event +async def on_message(message): + if message.author == client.user: + return + response = exec_cmd(message.content) + await message.channel.send(response) + +# bot code can run without connecting to Discord for testing +if TOKEN == None: + print("Running in test mode") + while True: + msg = input("user> ") + response = exec_cmd(msg) + print(response) +else: + client.run(TOKEN) diff --git a/cmd.py b/cmd.py @@ -0,0 +1,28 @@ +import random +from subprocess import Popen, PIPE + +from tweet import tweets + +def cowsay(msg): + process = Popen(["cowsay", msg], stdout=PIPE) + (output, err) = process.communicate() + exit_code = process.wait() + return '```\n' + output.decode('utf-8') + '```\n' + +def tweet(): + return random.choice(tweets) + +def fortune(): + process = Popen(["fortune"], stdout=PIPE) + (output, err) = process.communicate() + exit_code = process.wait() + return output.decode('utf-8') + + +def cowfortune(): + p1 = Popen(["fortune"], stdout=PIPE) + p2 = Popen(["cowsay"], stdin=p1.stdout, stdout=PIPE) + p1.stdout.close() + (output, err) = p2.communicate() + exit_code = p2.wait() + return '```\n' + output.decode('utf-8') + '```\n' diff --git a/config.sh b/config.sh @@ -0,0 +1,2 @@ +TMUX_SOCKET="botalan" +TMUX_SESSION="$TMUX_SOCKET" diff --git a/start.sh b/start.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +. ./config.sh + +BOTCMD="python3 botalan.py" + +echo "enter token:" +read -r TOKEN +TOKEN="$TOKEN" tmux -L $TMUX_SOCKET new -s $TMUX_SESSION -d $BOTCMD diff --git a/stop.sh b/stop.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +TMUX_SOCKET="botalan" +TMUX_SESSION="$TMUX_SOCKET" + +tmux -L botalan kill-session -t botalan diff --git a/tweet.py b/tweet.py @@ -0,0 +1,114 @@ +# tweets from my old shitposting twitter account +tweets = [ + "what are you talking about?", + "chicken, kentucky f", + "we were played for absolute fools", + "10 22 34 40 the numbers in my head\nand can't get them out", + "make it stop make it stop i never forget this i never", + "i want to forget", + "ha ha", + "nooo weather kinda popping tho", + "may", + "why when u say iq of 4 it's like bad but then gpa of 4 is good????", + "sports is crazy" + "good night i will talk to u tomorrow :)", + "gm there is a helicopter outside", + "eh maybe i'm feeling a little good rn", + "hola", + "i don't think this guy dostoevsky making shit up so sad", + "a pleasant breeze today", + "there are warrants for my arrest in 24 states and 13 foreign countries due to my weapons trafficking ring", + "i am currently on the run for sending weapons to west african rebel groups in order to control the uranium market", + "can i get a water with cream", + "I AM AN INSECT like a little fly go bzz bzzzzz around hanging out on a leaf in the nice weather we have today", + "happy friday", + "had a good day i saw the ocean it was nice tired from the week tho", + "feeling good confident about myself", + "some people i despise and i hold a great hatred to...\n\njohn mulaney\n\nstop having such an annoying voice john mulaney i'm talking to u, and try being funny some day as well", + "ever go to connecticut?", + "fuck i never want to go to connecticut", + "4 dogecoin", + "stop buying gas buy burrito with lots of beans then u get a nice food and then be making gas :)", + "I WILL never be known to the world I AM forever A SET OF CHARACTERS who changes in different situations\n\nNEVER WILL I BE KNOWN\n\nthe filth of this world does not provide reason to show\n\nYOU MAY THINK YOU KNOW ME\n\ni play along with the assumptions of those who despise me", + "someone stared at me today i think", + "noooooo i would say it is too warm outside now", + "good day", + "simp\n\nson\n\nwowwwwwwwww", + "it is good to be hopeful for tomorrow", + "have a good week :)", + "good weather today got burger", + "OH MOTHER I CAN FEEL THE SOIL FALLING OVER MY HEAD\nOH MOTHER I CAN FEEL THE SOIL FALLING OVER MY HEAD\nOH MOTHER I CAN FEEL THE SOIL FALLING OVER MY HEAD\nOH MOTHER I CAN FEEL THE SOIL FALLING OVER MY HEAD\nOH MOTHER I CAN FEEL THE SOIL FALLING OVER MY HEAD", + "there is a point where a tragedy becomes a comedy", + "the last vestiges of humanity have long disappeared", + "the big guy himself............?", + "NEVER NEVER NEVER I NEVER FORGET NEVER NEVER", + "I WANT TO FORGET", + "remember to brush your teeth", + "dog and fish little fishy fish", + "charlsday", + "dear fbi agents, all my posts are real, i am a threat to society", + "i have ascended", + "saturday", + "today was a good day", + "a little rain today", + "goooooooooooooooooooooooooooooooooooood morning vietnam", + "what is the reason", + "her: babe wyd\nme: just got ~\nher: what\nme: the home in unix\nher: wow u are a nerd let's kiss\n\nthis is not real", + "sometimes i need some time\non my own", + "my head is angry it is giving me pains", + "aaaaaahhhhhhhhhhhhh hey", + "when will it be warm outside for real", + "who am i", + "tfw i don't get a kiss for being irish", + "yea sometimes i'm irish", + "i don't like when there are people being mean and people fighting and wars", + "i piss on the shit", + "good morning a fine chewsday", + "why every night i am alone", + "almost 3pm now", + "am i doomer coomer bloomer i think i act like bloomer but in my mind probably like 70% doomer 25% coomer 5% bloomer", + "go to the beach where the weather is nice and the shells are pretty", + "tired", + "hey", + "happy", + "good morning have a good day everyone :)", + "heyyyyyyyyyyyyy", + "hi everyone how was your day", + "chewsday evening", + "hi it's some nice weather today i think", + "how fast are you gonna run as fast as a leopard lets see you do it", + "hi women thank you for existing ur great", + "go to college they said but i just want to live my own life!", + "i never actually been to kfc i been to five guys tho!", + "i cum in the fuck", + "oh how quaint....... NO STOP you put so many offices in my city!!! i think we lost our charm now just like anywhere else", + "to the cooler 20 days .....", + "good afternoon", + "fuck john mulaney", + "i have a burning, passionate hatred for john mulaney", + "hypothetically speaking if you touched a chicken nugget you touched a boob", + "thursday evenig", + "heyy hey hey don't", + "pondering", + "brooooooooooooooooo.............. hi", + "today is monday", + "need real human connection", + "unironically lonely rn", + "every minute i sit in this room i get weaker", + "whoever is reading this", + "woop woop woop wopp woop doo doo doo doo this is the end doo doo doo on a mission the man is crazy...", + "i think i should try to be serious for a while ahahah", + "sell the ice machine", + "fuck i have to pay taxes", + "hi i'm", + "looking for female i can go on a date to five guys with and play minecraft with me and laugh and be happy together 🥺", + "the tenn tonnnnnn truckkkkkkkkk", + "i never been to kfc my bad", + "i think too much coffee is what is causing my constant feeling of dehydration despite drinking like a gallon of water a day", + "hi", + "every monday feels like thursday and every tuesday feels like friday then wednesday will feel like monday thursday tuesday friday wednesday and then weekend", + "broooooooooooooooooo i want pumpkin pie rn", + "jjjkkkjjjhhhhjjkkjkllljhjkkjkjkkjkkihello<esc>wq", + "amazon is tripping rn", + "oh boy this is a scary day" +]