From 202047b6c2fbdbcf021d854cc342c48e41363142 Mon Sep 17 00:00:00 2001 From: dave Date: Sun, 16 May 2021 22:00:21 -0700 Subject: [PATCH] friends, load nicks from file, op mode --- cmd/swarm/main.go | 88 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 6 deletions(-) diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go index 50fdf1a..5efdb1b 100644 --- a/cmd/swarm/main.go +++ b/cmd/swarm/main.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "io/ioutil" "log" "math/rand" "net/http" @@ -16,14 +17,48 @@ import ( ) var insults = []string{"Leopard", "SailfinMolly", "NarwhalMan", "BluejayMan", "GiantCaveSwallow", "GreatHornedOwl", "SnappingTurtleMan", "Wolverine", "GiantAardvark", "SeaLamprey", "GrasshopperMan", "WhitebrowedGibbon", "GiantLouse", "RedwingedBlackbird", "Fairy", "LorikeetMan", "GiantSkunk", "GiantAlligator", "CaveFish", "Mosquito", "GiantFox", "SaltwaterCrocodileMan", "GiantOsprey", "Lion", "WeaselMan", "Human", "Swordfish", "ClownLoach", "DragonflyMan", "GiantMosquito", "SpongeMan", "GiantCopperheadSnake", "GiantBeetle", "KestrelMan", "BullShark", "AardvarkMan", "PeachfacedLovebirdMan", "GiantThrips", "Capybara", "Rutherer", "MaskedLovebirdMan", "KnuckleWorm", "OnehumpedCamelMan", "Deer", "Cassowary", "BaskingShark", "Wombat", "GiantSkink", "GiantMongoose", "EchidnaMan", "ParakeetMan", "HareMan", "BlackcrestedGibbon", "VultureMan", "Slug", "BushmasterMan", "GiantBobcat", "GiganticPanda", "CapybaraMan", "MagmaMan", "SquidMan", "GiantCrab", "ChinchillaMan", "GiantOstrich", "GiantWhiteStork", "GiantDeer", "RedPanda", "Siamang", "Dwarf", "GiantLeopard", "Bobcat", "Duck", "TwohumpedCamelMan", "GiantBeaver", "Troglodyte", "GiantRattlesnake", "RoachMan", "Satyr", "Albatross", "CheetahMan", "SpottedRatfish", "AdderMan", "GrayLangur", "CockatielMan", "GiantMuskox", "GiantKea", "CaveBlob", "GiantWren", "SeaNettleJellyfish", "GiantMoth", "GiantDingo", "SpiderMonkeyMan", "Oyster", "GiantMaskedLovebird", "GiantSaltwaterCrocodile", "GiantKoala", "BrownRecluseSpiderMan", "MoonSnailMan", "GiantMagpie", "FoxSquirrel", "GiantLionTamarin", "Halibut", "Clownfish", "BobcatMan", "Groundhog", "DarkGnome", "GiantCapuchin", "GiantPlatypus", "HamsterMan", "BrownRecluseSpider", "Harpy", "BloodGnat", "Molemarian", "GroundhogMan", "GiantGrayLangur", "Beetle", "GiantChinchilla", "Buzzard", "BlackMamba", "BeakDog", "Magpie", "DesertTortoiseMan", "ChameleonMan", "IguanaMan", "TigerMan", "BarkScorpion", "GiantAlbatross", "GiantTiger", "Guppy", "GiantSnappingTurtle", "Mantis", "Raccoon", "Cardinal", "RhesusMacaque", "RatMan", "GiantOcelot", "GiantGrizzlyBear", "MountainGoatMan", "Carp", "Beaver", "Tiger", "GiantOtter", "ToadMan", "GreatBarracuda", "MonarchButterfly", "Thrips", "SlugMan", "GiantCaveToad", "GreenTreeFrog", "Moghopper", "GiantKingsnake", "KingCobraMan", "SpermWhaleMan", "Capuchin", "PondGrabber", "MooseCow", "Vulture", "RhinocerosMan", "BlackMambaMan", "GiantBat", "GiantAxolotl", "WhitetipReefShark", "GiantOrca", "Louse", "GrayLangurMan", "Snail", "Tapir", "Herring", "Nautilus", "SeaOtter", "Anole", "SkunkMan", "TwohumpedCamel", "GiantMooseBull", "RedPandaMan", "Damselfly", "Orca", "FlyingSquirrel", "KoalaMan", "GreenDevourer", "WildBoar", "Ibex", "GiantLion", "SeaSerpent", "ReptileMan", "LizardMan", "GiantNarwhal", "GiantMandrill", "Perch", "Oriole", "Hamster", "GiantRat", "GiantRaven", "Wagon", "GiantLizard", "GiantCougar", "Axolotl", "GiantWeasel", "WrenMan", "Creature", "GiantCardinal", "Kobold", "GiantEarthworm", "Cougar", "SnowyOwl", "BarnOwlMan", "PuffinMan", "GiantCoyote", "Hake", "GiantNautilus", "HornbillMan", "Bilou", "LeopardSealMan", "GreyParrotMan", "Unicorn", "GiantOpossum", "Stingray", "Bat", "Kangaroo", "GiantMooseCow", "PurringMaggot", "Impala", "CaveFloater", "Horse", "SwanMan", "Gazelle", "FoulBlendec", "LouseMan", "Elk", "Llama", "PorcupineMan", "PeregrineFalcon", "Lorikeet", "NakedMoleDog", "CaveSpider", "MagpieMan", "CrabMan", "GiantGilaMonster", "GiantCapybara", "Lizard", "HoaryMarmotMan", "WolfMan", "Kingsnake", "CapuchinMan", "GiantAnaconda", "GiantHornbill", "GiantToad", "NautilusMan", "GiantGraySquirrel", "TapirMan", "GiantSnowyOwl", "Bushtit", "GiantWalrus", "GiantOriole", "GiantParakeet", "HoneyBadger", "Cyclops", "SpinyDogfish", "Coati", "GiantRedSquirrel", "WhitespottedPuffer", "OspreyMan", "MothMan", "Chimpanzee", "Mink", "Walrus", "Tigerfish", "GiantDesertTortoise", "DeerMan", "BlueJay", "Sole", "Cat", "ElkMan", "Cow", "IceWolf", "Fly", "Crow", "BatRay", "MagmaCrab", "Angelshark", "Anchovy", "MonarchButterflyMan", "Bonobo", "BarnOwl", "GiganticTortoise", "Seahorse", "Badger", "GilaMonsterMan", "Hydra", "BarkScorpionMan", "Mussel", "WhaleShark", "FireSnake", "GrizzlyBearMan", "LongfinMakoShark", "BuzzardMan", "GrackleMan", "SaltwaterCrocodile", "ElephantSealMan", "Leech", "Koala", "OrcaMan", "LeopardGeckoMan", "GiantBarnOwl", "CongerEel", "GiantSwan", "ElephantSeal", "BlackhandedGibbon", "BeetleMan", "Alpaca", "MantisMan", "GiantSlothBear", "BloodMan", "RedSquirrelMan", "GiantEmu", "GiantCaveSpider", "OpossumMan", "PandaMan", "GiantMole", "Yeti", "OcelotMan", "ArmadilloMan", "Parakeet", "BlackBullhead", "RedSquirrel", "Ant", "Antman", "Merperson", "GiantBrownRecluseSpider", "GiantMantis", "GiantRoach", "GiantPorcupine", "GiantTortoiseWoman", "HyenaMan", "GiantRhesusMacaque", "Shad", "GiantBluejay", "Cavy", "GiantElk", "Hagfish", "Hedgehog", "CaveSwallow", "GiantMonarchButterfly", "MonitorLizard", "GiantWarthog", "HarpSealMan", "SlothBearMan", "Char", "Goose", "Crundle", "Gorlak", "Ocelot", "PondTurtle", "Hippo", "GiantHippo", "Aardvark", "Donkey", "Giraffe", "ThornbackRay", "GiantDamselfly", "Echidna", "LargeRat", "Elf", "Kea", "PileatedGibbon", "MinkMan", "Reindeer", "GiantAdder", "JumpingSpider", "LionMan", "Crab", "JumpingSpiderMan", "AnacondaMan", "GiantHyena", "GiantGreatHornedOwl", "AmethystMan", "SlothMan", "WolverineMan", "GiantRedwingedBlackbird", "Ayeaye", "Ostrich", "GiantKangaroo", "Yak", "Bluefish", "PythonMan", "MoonSnail", "GiantKestrel", "CaveFishMan", "Loon", "Draltha", "BeaverMan", "GiantEagle", "KakapoMan", "Rat", "OrioleMan", "MosquitoMan", "GiantBushtit", "GiantChameleon", "GrizzlyBear", "TwoleggedRhinoLizard", "PeachfacedLovebird", "FlyingSquirrelMan", "CassowaryMan", "GiantGroundhog", "ForgottenBeast", "MooseBull", "CaveDragon", "SilveryGibbon", "GiantKiwi", "HoaryMarmot", "Guineafowl", "LargeRoach", "GiantSloth", "SlothBear", "GiantLoon", "CapHopper", "GiantKingCobra", "Puffin", "GiantAnole", "Octopus", "LionTamarin", "PenguinMan", "FireMan", "CuttlefishMan", "CreepingEye", "Bumblebee", "Coyote", "Wren", "GiantPolarBear", "KeaMan", "Jackal", "Adder", "MonitorLizardMan", "Milkfish", "HorseshoeCrabMan", "HarpSeal", "BrownBullhead", "MountainGoat", "FrillShark", "GiantSponge", "Termite", "MountainGnome", "ChipmunkMan", "GiantGrasshopper", "Sasquatch", "Dragon", "Bugbat", "WhiteStork", "OctopusMan", "EmuMan", "GiantGrackle", "PondTurtleMan", "CoyoteMan", "HammerheadShark", "Swan", "GiantPangolin", "KingCobra", "LynxMan", "Weasel", "GilaMonster", "Skunk", "AlligatorMan", "DemonRat", "Panda", "Chinchilla", "RainbowTrout", "GiantTick", "FoxMan", "GiantPenguin", "PhantomSpider", "Opah", "Iguana", "MuskoxMan", "Hornbill", "TooSmallForPressurePlates", "GiantLeopardGecko", "BronzeColossus", "Goat", "Mule", "RattlesnakeMan", "WarthogMan", "KiwiMan", "GiantVulture", "GiantLorikeet", "WalrusMan", "RedwingedBlackbirdMan", "Eagle", "Olm", "DamselflyMan", "MooseMan", "DesertTortoise", "Stoat", "CardinalMan", "BushtitMan", "Python", "GiantPondTurtle", "Ogre", "GiantPython", "GiantIguana", "EmperorPenguin", "GiantLeopardSeal", "GrayGibbon", "WormMan", "BluePeafowl", "GiantDragonfly", "Kestrel", "GiantWolverine", "GiantOlm", "GiantPeregrineFalcon", "CopperheadSnake", "GreenTreeFrogMan", "GreyParrot", "FlyMan", "WaterBuffalo", "GiantEchidna", "GiantWolf", "BrookLamprey", "PolarBearMan", "GiantBuzzard", "Pig", "Troll", "SeaMonster", "GiantTwohumpedCamel", "CoatiMan", "IbexMan", "GreatHornedOwlMan", "GiantCheetah", "WhiteStorkMan", "Chipmunk", "MudMan", "GiantCassowary", "SparrowMan", "RodentMan", "PangolinMan", "StoatMan", "KangarooMan", "Sparrow", "WombatMan", "GiantBlackMamba", "CaveCrocodile", "GiantCuttlefish", "MaskedLovebird", "GiantAyeaye", "Skink", "Alligator", "GiantSpiderMonkey", "GiantCoati", "ElkBird", "MandrillMan", "Sloth", "OstrichMan", "Gorilla", "Mandrill", "LeechMan", "Tick", "GiantKakapo", "GiantHoaryMarmot", "VoraciousCaveCrawler", "Lungfish", "GiantTortoise", "OtterMan", "Minotaur", "GiantMountainGoat", "GiantElephantSeal", "TickMan", "ElephantSealWoman", "GiantHedgehog", "CreepyCrawler", "MooseWoman", "Sponge", "GiantCockatiel", "Orangutan", "BlackBear", "LeopardSeal", "GiantLynx", "IronMan", "Coelacanth", "SpermWhale", "JackalMan", "Porcupine", "SteelheadTrout", "BlindCaveBear", "PlumpHelmetMan", "NurseShark", "HungryHead", "SpottedWobbegong", "CommonSkate", "Dragonfly", "Mackerel", "RaccoonMan", "GiantGazelle", "RhesusMacaqueMan", "GiantFly", "AcornFly", "AlbatrossMan", "MantaRay", "OceanSunfish", "GiantFlyingSquirrel", "WildBoarMan", "Pixie", "Sheep", "Fox", "HoneyBee", "GiantGrouper", "GreatWhiteShark", "Narwhal", "SerpentMan", "BadgerMan", "Grimeling", "Chicken", "GiantHamster", "GiantBushmaster", "Jabberer", "MongooseMan", "Moth", "Strangler", "Drunian", "GabbroMan", "BluefinTuna", "GiantJaguar", "Hare", "Muskox", "Rhinoceros", "GiantTiercelPeregrine", "Grackle", "Giant", "CaveSwallowMan", "GazelleMan", "TooBigForPressurePlates", "GiantHarpSeal", "Mongoose", "TigerShark", "Squid", "Salmon", "Dog", "Dingo", "GiantOnehumpedCamel", "GiantLeech", "BlindCaveOgre", "CommonSnappingTurtle", "Jaguar", "KingsnakeMan", "GraySquirrel", "Goblin", "BlacktipReefShark", "GiantHare", "Penguin", "Armadillo", "Pangolin", "GiantChipmunk", "LongnoseGar", "RavenMan", "HelmetSnake", "GiantPeachfacedLovebird", "Flounder", "Turkey", "Manera", "GiantHorseshoeCrab", "AyeayeMan", "AlligatorSnappingTurtle", "Worm", "LittlePenguin", "CopperheadSnakeMan", "PlatypusMan", "Toad", "Lynx", "BlizzardMan", "GiantHoneyBadger", "LoonMan", "Glasseye", "HoneyBadgerMan", "GiantGreyParrot", "LionTamarinMan", "Grasshopper", "Cuttlefish", "HippoMan", "Chameleon", "Anaconda", "GiantRaccoon", "GiantBlackBear", "RiverOtter", "HedgehogMan", "GiantMoonSnail", "CougarMan", "Nightwing", "Osprey", "GiantSpermWhale", "OlmMan", "GiantTapir", "GiantRhinoceros", "ImpalaMan", "Warthog", "SkinkMan", "Roc", "Emu", "GiantRedPanda", "FireflyMan", "GiantWildBoar", "BlueShark", "Cod", "Wolf", "GiantJackal", "HorseshoeCrab", "Raven", "GiantSparrow", "GiantWombat", "YellowBullhead", "Platypus", "AmphibianMan", "LeopardMan", "GiantSlug", "GiantArmadillo", "Reacher", "Ettin", "JaguarMan", "FluffyWambler", "TooBigForBridges", "EagleMan", "CaveLobster", "GiantMonitorLizard", "Kiwi", "CrowMan", "GiantStoat", "Kakapo", "GiraffeMan", "Rattlesnake", "OnehumpedCamel", "GiantJumpingSpider", "GiganticSquid", "Elephant", "SnowyOwlMan", "ThripsMan", "Cheetah", "GiantElephant", "SnailMan", "ShortfinMakoShark", "GiantBarkScorpion", "Gremlin", "BatMan", "Opossum", "FireImp", "FleshBall", "Pike", "BlackBearMan", "GiantPuffin", "PolarBear", "ElephantMan", "SpiderMonkey", "FloatingGuts", "PeregrineFalconMan", "GiantImpala", "AxolotlMan", "GiantFirefly", "Hyena", "Sturgeon", "WhitehandedGibbon", "GiantSnail", "GiantOctopus", "Marlin", "GiantGreenTreeFrog", "Bushmaster", "Cockatiel", "GiantBadger", "GiantCrow", "Rabbit", "GiantMink", "BandedKnifefish", "LeopardGecko", "AnoleMan", "GraySquirrelMan", "Firefly", "GiantIbex", "GiantGiraffe", "GiantTortoiseMan", "DingoMan"} +var friends = []string{} var s = rand.NewSource(time.Now().UnixNano()) // initialize global pseudo random generator var r = rand.New(s) var channel string var victim string var is_connected = false +var op_mode = false var greetChance = 100 var suffixLength = 0 +func loadFriends() { + friendsV := os.Getenv("IRC_EXTRAFRIENDS") + if friendsV == "" { + return + } + for _, name := range strings.Split(strings.TrimSpace(friendsV), ",") { + name := strings.TrimSpace(name) + if name != "" { + log.Printf("loaded extra friend: %s", name) + friends = append(friends, name) + } + } +} + +func loadNames(fpath string) { + content, err := ioutil.ReadFile(fpath) + if err != nil { + panic(err) + } + insults = []string{} + for _, line := range strings.Split(string(content), "\n") { + stripped := strings.TrimSpace(line) + if stripped != "" { + log.Printf("loaded name: %s", stripped) + insults = append(insults, stripped) + } + } + if len(insults) == 0 { + panic(fmt.Errorf("no names loaded from %s", fpath)) + } +} + func getNumericVar(key string, default_ int) int { varS := os.Getenv(key) if varS != "" { @@ -36,13 +71,34 @@ func getNumericVar(key string, default_ int) int { return default_ } +func friendlyNick(nick string) bool { + for _, n := range friends { + if nick == n { + return true + } + } + for _, n := range insults { + if strings.HasPrefix(nick, n) { + return true + } + } + if strings.HasPrefix(nick, "Op") { + return friendlyNick(nick[2:]) + } + return false +} + func genNick() string { - return insults[r.Intn(len(insults))] + trailingDigits(suffixLength) + n := insults[r.Intn(len(insults))] + trailingDigits(suffixLength) + if op_mode { + n = "Op" + n + } + return n } func trailingDigits(length int) string { trailing := "" - for ; length > 0 ; length -- { + for ; length > 0; length-- { trailing = fmt.Sprintf("%s%d", trailing, r.Intn(10)) } return trailing @@ -84,6 +140,11 @@ func HandleRequest(ctx context.Context) (string, error) { if victim == "" { log.Fatal("Set IRC_VICTIM!") } + enable_op_mode := os.Getenv("IRC_OP_MODE") + if enable_op_mode != "" { + op_mode = true + } + suffixLength = getNumericVar("SUFFIX_DIGITS", 0) if suffixLength < 0 || suffixLength > 10 { panic(fmt.Errorf("invalid SUFFIX_DIGITS: %d", suffixLength)) @@ -112,6 +173,7 @@ func HandleRequest(ctx context.Context) (string, error) { } func handleIRCCon(c *irc.Client, m *irc.Message) { + log.Printf("%+v\n", m) sent := 0 // Only one reader, prob not necessary @@ -120,7 +182,6 @@ func handleIRCCon(c *irc.Client, m *irc.Message) { is_connected = true // 001 is welcome event c.Write("JOIN " + channel) - } else if m.Command == "PRIVMSG" && c.FromChannel(m) { // Handle chat message to print stats text := strings.Split(m.Trailing(), " ") @@ -149,7 +210,7 @@ func handleIRCCon(c *irc.Client, m *irc.Message) { }*/ } else if m.Command == "JOIN" && c.FromChannel(m) { if m.Prefix.Name != c.CurrentNick() { - if greetChance == 100 || r.Intn(100) < greetChance { + if greetChance == 1000 || r.Intn(1000) < greetChance { c.WriteMessage(&irc.Message{ Command: "PRIVMSG", Params: []string{ @@ -158,10 +219,19 @@ func handleIRCCon(c *irc.Client, m *irc.Message) { }, }) } + if op_mode && friendlyNick(m.Prefix.Name) { + log.Printf("opping %s", m.Prefix.Name) + c.WriteMessage(&irc.Message{ + Command: "MODE", + Params: []string{ + m.Params[0], + "+o", + m.Prefix.Name, + }, + }) + } } } - - log.Printf("%+v\n", m) } func main() { @@ -170,6 +240,12 @@ func main() { log.Fatalf("invalid GREET_CHANCE: '%s'", greetChance) } + namesPath := os.Getenv("NAMES_FPATH") + if namesPath != "" { + loadNames(namesPath) + } + loadFriends() + go runStatusHandler() ctx, _ := context.WithCancel(context.Background()) ret, err := HandleRequest(ctx)