diff --git a/boy b/boy new file mode 100644 index 0000000..2a40882 --- /dev/null +++ b/boy @@ -0,0 +1 @@ +nyaa~~ diff --git a/cmds/.tw.un~ b/cmds/.tw.un~ new file mode 100755 index 0000000..ceef115 Binary files /dev/null and b/cmds/.tw.un~ differ diff --git a/cmds/arguments b/cmds/arguments new file mode 100755 index 0000000..07d075c --- /dev/null +++ b/cmds/arguments @@ -0,0 +1,6 @@ +#!/bin/sh + +echo -n "\$1 => " ; test -z "$1" && echo -n " | " || echo -n "$1 | " +echo -n "\$2 => " ; test -z "$2" && echo -n " | " || echo -n "$2 | " +echo -n "\$3 => " ; test -z "$3" && echo -n " | " || echo -n "$3 | " +echo -n "\$4 => " ; test -z "$4" && echo -n " | " || echo -n "$4 | " diff --git a/cmds/echo b/cmds/echo new file mode 100755 index 0000000..3133778 --- /dev/null +++ b/cmds/echo @@ -0,0 +1,2 @@ +#!/bin/sh +echo $1 diff --git a/cmds/fruit b/cmds/fruit new file mode 100755 index 0000000..c5bb42e --- /dev/null +++ b/cmds/fruit @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 + +import random +from io import StringIO + +base = 0x1f345 +nSides = 14 +rounds = 14 +fp = StringIO() + +for i in range(rounds): + roll = random.randint(0, nSides) + chcr = base + roll + fp.write(chr(chcr)) + +print(fp.getvalue()) diff --git a/cmds/greet b/cmds/greet new file mode 100755 index 0000000..d2ec74f --- /dev/null +++ b/cmds/greet @@ -0,0 +1,2 @@ +#!/bin/sh +echo hi $2 from $3 diff --git a/cmds/help b/cmds/help new file mode 100755 index 0000000..1d068f4 --- /dev/null +++ b/cmds/help @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 +import sys +if len(sys.argv) > 1 and sys.argv[1] == "writing": + print("you can add new scripts to our by placing executable files in the /town/our directory. Make sure they have the +x permission. programs are passed these arguments by the bot: the arguments given in the message (our/[program] [args]), the user ID, and the channel it was run from.") +else: + print("the our bot allows smol programs written by townies to be used by typing \"our/[program]\" from IRC. See also \"our/help writing\"") diff --git a/cmds/howami b/cmds/howami new file mode 100755 index 0000000..bb8b0db --- /dev/null +++ b/cmds/howami @@ -0,0 +1,2 @@ +#!/bin/sh +echo "You're doing great." diff --git a/cmds/jikan b/cmds/jikan new file mode 100755 index 0000000..63a54f7 --- /dev/null +++ b/cmds/jikan @@ -0,0 +1,17 @@ +#!/usr/bin/env hy3 + +(import [datetime [datetime]]) + +(setv fullwidth (str.maketrans + (dfor [i ch] (enumerate "0123456789") [(str i) ch]))) + +(setv weekdays "日月火水木金土") (comment 曜日) + +(defn ctime [] + (setv d (datetime.now)) + (-> (.format "{}年{}月{}日 {:02d}:{:02d}:{:02d}" + d.year d.month d.day d.hour d.minute d.second) + (.translate fullwidth))) + +(print (ctime)) + diff --git a/cmds/ls b/cmds/ls new file mode 100755 index 0000000..be32eff --- /dev/null +++ b/cmds/ls @@ -0,0 +1,4 @@ +#!/bin/sh +DIR=$(dirname -- $0) +find $DIR/* -maxdepth 1 -perm -111 -type f -printf "%f " +echo diff --git a/cmds/qotd b/cmds/qotd new file mode 100755 index 0000000..284b2a8 --- /dev/null +++ b/cmds/qotd @@ -0,0 +1,2 @@ +#!/bin/sh +nc localhost 17 -W 1 diff --git a/cmds/rev b/cmds/rev new file mode 100755 index 0000000..54157d7 --- /dev/null +++ b/cmds/rev @@ -0,0 +1,3 @@ +#!/bin/sh +echo "$1"|rev + diff --git a/cmds/roll b/cmds/roll new file mode 100755 index 0000000..b11f1be --- /dev/null +++ b/cmds/roll @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +# A simple dice rolling app +# Written by xaphania 2022-04-19 +# v0.1.our +# modified for use with the our irc bot 2022-04-21 +# yes this probably sucks. please send your flames to xaphania@tilde.town + +import random +import sys + +try: + dstring = sys.argv[1] +except: + dstring = "1d6" + +try: + numDice = int(dstring.split("d",1)[0]) + numFace = int(dstring.split("d",1)[1]) +except: + print(f"{dstring} is not a valid dice format") + exit() + +diceList=[] + +while numDice>0: + diceList.append(random.randint(1,numFace)) + numDice-=1 + +total = sum(diceList) +avg = total / len(diceList) +high = max(diceList) +low = min(diceList) + +print (f"Result: {diceList} | Total: {total} Average: {avg} Highest: {high} Lowest: {low}") diff --git a/cmds/room b/cmds/room new file mode 100755 index 0000000..6700f90 Binary files /dev/null and b/cmds/room differ diff --git a/cmds/room.go b/cmds/room.go new file mode 100644 index 0000000..b540a71 --- /dev/null +++ b/cmds/room.go @@ -0,0 +1,89 @@ +package main + +import ( + "fmt" + "math/rand" + "time" +) + +func randStr(s []string) string { + return s[rand.Intn(len(s))] +} + +func airQuality() string { + return randStr([]string{ + "moist", + "warm", + "humid", + "cool", + "dry", + "electric", + "dusty", + "hazy", + "smoky", + "clear", + }) +} + +func wallType() string { + return randStr([]string{ + "bronze", + "mossy stone", + "wet stone", + "copper", + "tile", + "hard wood", + "stained wood", + "purple", + "light blue", + "yellowed", + "vine choked", + "art hung", + }) +} + +func lightQuality() string { + return randStr([]string{ + "dimly lit", + "brightly lit", + "faintly lit", + "covered in dancing shadows", + "dappled", + }) +} + +func lightSource() string { + return randStr([]string{ + "candle light", + "bioluminescent moss", + "bioluminescent fungus", + "lantern light", + "flickering monitors", + "a cracked LCD", + "a fireplace", + "a torch", + "sconces", + }) +} + +func aroma() string { + return randStr([]string{ + "lavender", + "cloves", + "sulphur", + "baking cookies", + "dirt", + "wet soil", + "cut grass", + "wet dog", + "cinnamon", + "swamp", + "moss", + }) +} + +func main() { + rand.Seed(time.Now().UTC().UnixNano()) + fmt.Printf("the air is %s. %s walls are %s by %s. it smells faintly of %s.\n", + airQuality(), wallType(), lightQuality(), lightSource(), aroma()) +} diff --git a/cmds/rot13 b/cmds/rot13 new file mode 100755 index 0000000..6bbecd5 --- /dev/null +++ b/cmds/rot13 @@ -0,0 +1,3 @@ +#!/bin/sh +echo "$1"|rot13 + diff --git a/cmds/sh b/cmds/sh new file mode 100755 index 0000000..8ef3dca --- /dev/null +++ b/cmds/sh @@ -0,0 +1,2 @@ +#!/bin/sh +sh -c "$1" diff --git a/cmds/time b/cmds/time new file mode 100755 index 0000000..42b938a --- /dev/null +++ b/cmds/time @@ -0,0 +1,11 @@ +#!/bin/sh + +#echo "arguments are 1:$1 2:$2 3:$3 4:$4" +args="$1"; +user="$2"; +channel="$3"; +nick="$(echo "$user"|cut -d "!" -f 1)" +args_lower="$(echo "$args"|tr [:upper:] [:lower:])" +case "$args_lower" in + ("to shine") echo "yo, $nick, 🌟💎shine bright like a diamond!💎🌟";; +esac diff --git a/cmds/timefor b/cmds/timefor new file mode 100755 index 0000000..c81b353 --- /dev/null +++ b/cmds/timefor @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +echo $2 + +ip=$(finger $1 | egrep -o -m 1 '([0-9]{1,3}\.){3}[0-9]{1,3}') +tz=$(curl -s "https://ipapi.co/$ip/timezone") +TZ=$tz date -R diff --git a/cmds/tw b/cmds/tw new file mode 100755 index 0000000..9b11432 --- /dev/null +++ b/cmds/tw @@ -0,0 +1,5 @@ +#!/bin/bash +user="$2" +nick="$(echo "$user"|cut -d "!" -f 1)" +/home/jmjl/bin/tw -u $nick $1 | sed -z 's/\n/ - /g' +# /home/jmjl/bin/tw -u $nick $1 diff --git a/cmds/uptime b/cmds/uptime new file mode 100755 index 0000000..780bb61 --- /dev/null +++ b/cmds/uptime @@ -0,0 +1,2 @@ +#!/bin/sh +uptime diff --git a/cmds/weather b/cmds/weather new file mode 100755 index 0000000..c316f77 --- /dev/null +++ b/cmds/weather @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +###################################################### +# Takes a location, e.g. "New York" as an argument # +# and returns the current weather conditions. Uses # +# the weather data API courtesy of metaweather.com # +###################################################### + +###################################################### +# Written by ~xaphania 2022-04-22 # +# For use on tilde.town with the 'our' IRC bot # +# Please send comments or suggestions via town mail # +# to xaphania@tilde.town # +# v0.1 # +# TO DO - customise weather strings, add emoji? # +# TO DO - more features: detailed reports, future # +# and past weather conditions, etc # +###################################################### + +import sys +import json +import urllib.request + +# get argument, replace spaces with %20 +search = sys.argv[1].replace(" ","%20") + +# Get Where on Earth ID for specified location +searchUrl = "https://www.metaweather.com/api/location/search/?query=" + search + +try: + locationData = json.loads(urllib.request.urlopen(searchUrl).read()) +except: + print("Couldn't contact metaweather. Service may be down, please try later.") + exit() +try: + locationID = locationData[0]["woeid"] +except: + search = search.replace("%20"," ") + print(f"Sorry, I couldn't find location {search}") + exit() + +# Get weather data for that woeid +weatherUrl = "https://www.metaweather.com/api/location/"+str(locationID)+"/" + +try: + weatherData = json.loads(urllib.request.urlopen(weatherUrl).read()) +except: + print("Couldn't contact metaweather. Service may be down, please try later.") + exit() + +try: + state = weatherData["consolidated_weather"][0]["weather_state_name"] + temp = round(weatherData["consolidated_weather"][0]["the_temp"]) + location = weatherData["title"] + parent = weatherData["parent"]["title"] + print(f"In {location}, {parent} it's {temp}°c and {state}" \ + +" (Weather Data from www.metaweather.com)") + +except: + print("Sorry, there was an error retreiving weather data. Please try later.") + diff --git a/cmds/whatami b/cmds/whatami new file mode 100755 index 0000000..be8e1dd --- /dev/null +++ b/cmds/whatami @@ -0,0 +1,2 @@ +#!/bin/sh +echo "A human (most likely)" diff --git a/cmds/whenami b/cmds/whenami new file mode 100755 index 0000000..31b283c --- /dev/null +++ b/cmds/whenami @@ -0,0 +1,2 @@ +#!/bin/sh +date diff --git a/cmds/whereami b/cmds/whereami new file mode 100755 index 0000000..eef5755 --- /dev/null +++ b/cmds/whereami @@ -0,0 +1,2 @@ +#!/bin/sh +echo $3 diff --git a/cmds/whoami b/cmds/whoami new file mode 100755 index 0000000..6693a35 --- /dev/null +++ b/cmds/whoami @@ -0,0 +1,2 @@ +#!/bin/sh +echo $2 diff --git a/cmds/whyami b/cmds/whyami new file mode 100755 index 0000000..a1cc873 --- /dev/null +++ b/cmds/whyami @@ -0,0 +1,2 @@ +#!/bin/sh +echo "https://en.wikipedia.org/wiki/Meaning_of_life" diff --git a/our.rb b/our.rb new file mode 100755 index 0000000..a0e71b8 --- /dev/null +++ b/our.rb @@ -0,0 +1,102 @@ +#!/usr/bin/env ruby +require 'socket' +require 'open3' + +module IRC + +class User + attr_accessor :s + + def initialize addr, port, nick + @hooks = [] + + @s = TCPSocket.open addr, port.to_s + s.puts "USER #{nick} fakehost whatevenisaservername :beep boop" + s.puts "NICK #{nick}" + + hook do |m| + next unless m.cmd == 'PING' + raw "PING #{nick}" + end + end + + def raw msg + @s.puts msg + end + + def join chan + raw "JOIN #{chan}" + end + + def privmsg target, msg + raw "PRIVMSG #{target} :#{msg}" + end + + def hook &h + @hooks << h + end + + def loop + while line = s.gets + msg = Message.new line + @hooks.each{|h| h.call(msg)} + end + end +end + +class Message + attr_accessor :prefix, :cmd, :args, :raw + # TODO custom constructor + def initialize msg + msg = msg.delete_suffix "\r\n" + @raw = msg + @prefix = nil + @prefix, msg = msg[1..].split(' ', 2) if msg[0] == ':' + @cmd, msg = msg.split(' ', 2) + + @args = [] + while msg and not msg.empty? + if msg[0] == ':' + @args << msg[1..] + break + end + s, msg = msg.split(' ', 2) + @args << s + end + end +end + +end + +puts "starting" +i = IRC::User.new 'localhost', 6667, 'our' +i.join '#tildetown' +i.join '#bots' +i.hook do |msg| + next unless msg.cmd == 'PRIVMSG' + target, content = msg.args + next unless content.delete_prefix! 'our/' + + cmd, args = content.split(' ', 2) + cmd = '/town/our/' + cmd + args ||= '' + next unless File.exists? cmd + if not File.executable? cmd + i.privmsg target, "#{cmd} isn't executable. try chmod +x" + next + end + + begin + # child = IO.popen [cmd, args, msg.prefix, target] + # out = child.gets + # child.close + Open3.popen2e(cmd, args, msg.prefix, target) {|_, stdout, _| + out = stdout.gets + i.privmsg target, out if out + } + rescue Exception => e + i.privmsg target, "[our.rb] #{e.to_s}" + end + next true +end +i.loop diff --git a/passwd b/passwd new file mode 100644 index 0000000..0f6016f --- /dev/null +++ b/passwd @@ -0,0 +1,2 @@ +root:x:0:0:root:/root:/bin/ed +weed:x:420:666:lmao:/weed:/bin/mount.ext4