And it seems I got a bonus bug here! Why doesn't the second set of [quote]
s render?
Posts made by hhaamu
-
RE: Nested quotes are halfway eaten when trying to quote
-
RE: Nested quotes are halfway eaten when trying to quote
@our favourite ranty rodent said:
a very ranty reply
this is a test post.
@our favourite ranty rodent said:
@not PJH said:
continuing post 1. this quotes normally.
continuing ranty reply 1So if you quote this post, the first nested quote gets eaten. I think.
...And it did. Whee. Bug or feature?
-
RE: Nested quotes are halfway eaten when trying to quote
@our favourite ranty rodent said:
@not PJH said:
post 1; this gets swallowed
a very ranty replythis is a test post.
@our favourite ranty rodent said:
@not PJH said:
continuing post 1. this quotes normally.
continuing ranty reply 1So if you quote this post, the first nested quote gets eaten. I think.
-
Nested quotes are halfway eaten when trying to quote
I'm not sure this discobug is known yet, but I've noticed that when you quote a post ('Quote whole post') with nested quotes, the innermost quote gets eaten. Only for the first quote block though; the rest get through correctly.
Of course, it's very possible that it's a discofeature.
I'll try to make a sample post.
-
RE: Longest post in Discourse history?
That strips any formatting the post may have had. I think it also has some sort of focus issues I haven't been quite able to pin down yet.
-
RE: Longest post in Discourse history?
But let's re-rail this topic again. Is there any way we can make lengthy posts with quoting somehow easier? I really hate typing
[/quote][quote]
all the time to respond to a particular part of a post; the syntax is the same as bbcode's which is stupid as hell as a markup language. -
RE: Longest post in Discourse history?
Yeah, I did mean that they do wrap, but I get much longer lines than reasonable with that CSS. They should be ~80-100 characters wide at most. Basically, I don't want the 'widescreen' part.
-
RE: Longest post in Discourse history?
Hence the reason for the
Widescreen+min
CSS style:So we're down from ~180 px of vertical space to ~135 px of vertical space (and that's still ~70-90 px extra), for a one-line post. But then I'd have to deal with the lines never wrapping. What's up with that?
There's a reason why I put
p { max-width: 30em; }
on any CSS I write. -
RE: Enlightened
Or are you saying he needs a dedicated PR department to tell him, "hey, moron, what are you doing here? How does this help anything? Get a fucking grip!"
I was saying that the responses ChrisH was hoping for reeked of a PR department's feel-good style, not of an actual engineer who knows the product.
-
RE: Enlightened
If it were that PR department speaking, they'd give that "We value your input but aren't going to do a damn thing about anything you mentioned" feel-good response.
Also, I'm treating EFL as an open source project, not something owned by Samsung. Yes, I know, Samsung has paid for its development for the past five-ish years, but that's only a third of its existence.
-
RE: Enlightened
It's foolish to expect any single person to have the courtesy of a big company with a dedicated PR department -- especially when you are not paying them.
-
RE: Enlightened
Oh, I wasn't aware that QWERTZ was used in central-ish/south-ish/east-ish Europe. (Er, countries mostly north-west of Greece.) I thought it was for Germans only. The German layout has curlywigs in the usual position.
-
RE: Enlightened
Aren't curlywigs usually in the number row? I've never seen one under
B
. -
RE: Longest post in Discourse history?
Sounds like you've got an Asian font which have characters in the unicode private-use area. (It happens. Something about Han unification I guess?)
-
RE: Longest post in Discourse history?
I don't know. The last time I used it, it was still quite unsure whether it wanted to be a file browser or a web browser. It didn't really make a good experience for either. Besides, I have an aversion for installing half of KDE for a single application.
But I guess it's good to remember it exists.
-
RE: Longest post in Discourse history?
I'd have appreciated that image if you hadn't fetched it off wikipedia but made your own.
Oh, incidentally, I have looked at images (in a web browser) and watched videos on the Linux terminal prompt with the framebuffer. It was a looong time ago though.
-
RE: Longest post in Discourse history?
Sorry. It's the only browser nowadays that does not try to fuck with the UI.
-
RE: Longest post in Discourse history?
Incidentally, the f-l ligature is exactly what I want to click when I want to search!
-
RE: Longest post in Discourse history?
I don't consider downloadable fonts to be essential for web sites, much less forums. I love the editor now though.
-
RE: Longest post in Discourse history?
Wasn't one of those things Jeff bemoaned in his discourse manifesto that there's soo much whitespace on posts by traditional forums software?
I kind of get the same feeling with discourse, since everyone's making one- or two-line posts. There's still at least 50 % whitespace. And I have to scroll, a lot. On the positive side, at least it's not a 7-pt font.
(On an unrelated note, set
gfx.downloadable_fonts.enabled = false
and discourse becomes mystery meat navigation! I thought it was because I was missing some new unicode 8.0 font included in Vista or 7 but it was a web browser option I'd flipped.) -
RE: Enlightened
Oh, wow. Rasterman appeared. Do we have that Eterm author yet? Michael something IIRC?
This might be an interesting thread if the noise level wasn't so high. And half of the participants weren't dyed-in-the-wool C# programmers who hate open sauce and have never left Windows.
(Personally, I'm just impressed that rasterman & co spent ten years writing and rewriting the libraries for e17 before a real release. Anyone who can do that is dedicated.) (Yes, I'm afraid this is joke-bait. Bad thread for praising someone.)
-
RE: Enlightened
I went grepping for the code. The 'spank spank spank' I don't particularly find amusing, but it's not really as bad as your selective quoting makes it look like.
"*** Eina Magic Check Failed !!!\n" " Input handle has already been freed!\n" "*** NAUGHTY PROGRAMMER!!!\n" "*** SPANK SPANK SPANK!!!\n" "*** Now go fix your code. Tut tut tut!\n"
It appears your 'bitch' string is used in the sense of 'complaint' or 'gripe'; many comments say 'Evas bitches'. Never does it say 'you bitch'.
if (obj->smart.parent) { if (obj->smart.parent != below->smart.parent) { ERR("BITCH! evas_object_stack_below(), %p not inside same smart as %p!", obj, below); return; } evas_object_smart_member_stack_below(obj, below); } else
...they use the GNU brace style. I just came up with a strong aversion for the library.
-
RE: Enlightened
@hhaamu said:
[something about
show_all()
; discobug: first nested quote doesn't get quoted]
No, EFL doesn't have such functionality. You have to manually show every child of every widget. At least hiding works as expected - hiding the parent hides all children.Can't you at least foreach over the objects?
-
RE: Enlightened
@blakeyrat said:
EFL is a collection of libraries that are independent or may build on top of each-other
So they're either independent or interdependent, but the documentation writers are not quite sure which?It's a dependency hierarchy. Some parts of EFL have no dependencies. Others depend on each other. It's a fancy way of saying "Compile+install these first; the rest will fail to compile if their dependencies haven't been installed yet."
-
RE: Enlightened
Disclaimer: I've been looking at E17/EFL development from afar for a while; never actually used it.
1. Create a widget of type box with the background as a parent (obviously!), which is not really a widget but a layout, but it’s also not a layout because a layout in EFL is something totally different and it’s not a widget. As usual – it’s a hack for positioning widgets next to each other.
2. Show the box.
3. Create an Evas_Object of type button with the box as its parent.
4. Show the button.
5. Create a next Evas_Object of type button with the box as its parent.
6. Show the button.
7. Marvel at your two buttons which took you 50-100 lines of code to create.Some things in your post remind me of GTK. Are you sure you're not missing a
show_all()
function call? This is how you'd do it in GTK:my $window = Gtk2::Window->new; my $vbox = GTK2::VBox->new(...); $window->add($vbox); my $button1 = Gtk2::Button->new("_Foo"); my $button2 = Gtk2::Button->new("_Bar"); $vbox->pack_start($button1, ...); $vbox->pack_start($button2, ...); $window->show_all();
Not quite sure how you can get fifty lines out of it.
One example of this memory mismanagement is a thing called a Genlist. It in essence is a list widget with some items. It has a special “feature” – it deletes items when they go out of view and allocates memory for them when they get into view. Make a quick swipe on such list on your mobile device and you can actually hear your RAM scream in agony.
For example, a layout is immutable. You make it, you stick with it. That immutability is pretty far reaching.
These things halfway make sense, if you consider that the whole thing is designed for low memory usage and performance. (Kind of like what you'd want an UI library on a cell phone to be.)
-
RE: Google is being naughty
Might be only for us javascriptless people.
Also, while this thread is active: rate my Helvetica.
-
RE: Google is being naughty
My browser has
accept cookies for current session only
ticked so it's unlikely they're tracking me via cookies at least. 'sides, I primarily use the duck-themed search engine.Anyway, it wasn't a searchbar suggestion like yours are but one of those relatedsearches at the bottom of the results page.
-
Google is being naughty
I don't know if Google is profiling me or what, but I got these related search suggestions for an innocuous query.
...I sure hope that's not because of a profile they've built of me.
-
RE: Discourse SQL 1 minute query...
The lone recommendation on my mind would've been to make the exclusions join be done on as few rows as possible (i.e. not 10M). This requires splitting the aggregates into two:
WITH posts_read AS ( SELECT u.username, u.id AS user_id, log(2, foo.count) FROM ( SELECT agg.user_id, sum(agg.count) AS count FROM ( SELECT pt.* FROM ( SELECT pt.user_id, pt.topic_id, Count(*) AS count FROM post_timings pt GROUP BY 1, 2 ) pt LEFT JOIN exclusions e ON e.topic_id = pt.topic_id WHERE e.topic_id IS NULL ) agg GROUP BY agg.user_id ) foo JOIN users u ON u.id = foo.user_id )
I quite doubt it'll speed it up at all, if not actually slow it down.
-
RE: Discourse SQL 1 minute query...
That works, but of course doesn't exclude the spam topics.
Anyway, reading
posts_timings
and aggregating over it will take the 20+ seconds no matter what and it'll scale linearly and you'll likely be in this mire again once the table doubles in size within 6-12 months or so. Better try to software-engineer your way out -- you can't fix it by tweaking a single SQL query. -
RE: Discourse SQL 1 minute query...
Seven topics. Overhead from navigating a binary tree is way higher than just matching against those seven numbers over and over again.
-
RE: Discourse SQL 1 minute query...
Sadly each query is run independantly (think sandboxed) and I'm not allowed to modify the db environment like that.
temp tables are per-connection, so if you're not tearing down and reconnecting between each run, it should be doable. (Of course it depends on what you are 'allowed' to do.)
-
RE: Discourse SQL 1 minute query...
Frankly, I'm not all surprised that reading ten million rows from
post_timings
(takes 19 seconds) and joining them againstusers
(takes 52 seconds), and finally aggregating them (takes 20 seconds) takes that long.One flaw you have is doing the join against
users
before aggregating. The aggregating criteria is all in thepost_timings
table. Move the join a bit further about:WITH posts_read AS ( SELECT u.username, u.id AS user_id, agg.count, agg.ln2, agg.ln3 FROM ( SELECT user_id, count(*), log(2, count(*)) AS ln2, log(3.0, count(*)) AS ln3 FROM post_timings pt WHERE topic_id NOT IN ( SELECT topic_id FROM exclusions) GROUP BY user_id ) agg JOIN users u ON u.id = agg.user_id )
While I'm at it, let's convert the
NOT IN ()
into a left anti-join. (I doubt there's performance gain, but why not.)WITH posts_read AS ( SELECT u.username, u.id AS user_id, agg.count, agg.ln2, agg.ln3 FROM ( SELECT user_id, count(*), log(2, count(*)) AS ln2, log(3.0, count(*)) AS ln3 FROM post_timings pt LEFT JOIN exclusions e ON pt.topic_id = e.topic_id WHERE e.topic_id IS NULL GROUP BY user_id ) agg JOIN users u ON u.id = agg.user_id )
-
RE: Discourse SQL 1 minute query...
On a short notice, if all the queries start with those two CTEs, you would benefit the most by shoving their result into temporary tables at the start of a run and query those instead.
CREATE TEMPORARY TABLE exclusions AS SELECT ...
etc. -
RE: Discourse SQL 1 minute query...
I'll take a look at it, but my brains are all out of juice right now; might take a day or two.
-
RE: Alternate keyboard layouts
Dvorak user here.
If you're thinking of Dvorak because you want to get a higher WPM, don't. It didn't improve my speed over QWERTY at all. Around 90 WPM on both.
If you're thinking of Dvorak because of (wrist) comfort, that's probably a good reason to try it. (Just remember that your wrists will probably hurt until you've gotten the muscle memory down.)
The downsides:
-
You can't type with a single hand. The way the vowels are all placed on the left side will lead your fingers dancing all over the keyboard just to type a single word. (Yes, there are two one-hand Dvorak layouts. They're okay, but more learning.)
-
National Dvorak variants don't really exist. There are few Dvorak layouts with 'foreign' letters such as é or ø included in the layout. The layout's effectively confined to the English-speaking world.
One more positive thing about Dvorak is that some special oft-needed characters such as
[]{}
aren't hidden behind AltGr as they are in many European layouts. Makes coding a bit easier.As for games, I find that many take input at such a low level that they don't care which keyboard layout you use. It's always US English QWERTY to them. So no real need to redo keybindings.
-
-
RE: Sidebar WTF never opening
You know, it's definitely cooties in that there's a second symptom.
When this happens, all the articles on the front page say
0 Comments - Last Comment @ -none-
-- although sometimes it manages to have a timestamp for the non-existing last comment.And if I click the 0 comments link (e.g. this) to the 'comments preview' page, it says there are no comments yet. The
Continue this discussion on Dicsource
link on that page leads to a 404: http://what.thedailywtf.com/t//0Some sort of connectivity issue with the front page and the forums servers? All that's missing is PHP spewing out mysql_connect() errors except that this isn't PHP and there's no MySQL, thank
$ENV{DEITY}
-
RE: Sidebar WTF never opening
I'm getting these cooties all the time. Well, at least once a week. Right now, in fact. They generally fix themselves in a few hours.
FWIW, the relevant generated HTML on the main page is this:
<aside> <h5 class="heading"><a class="clean" href="#"><i class="icon-list"></i>Sidebar WTF</a></h5> <div class="articleList hideNonDesktop"> <ul> </ul> </div> </aside>
So, um, whatever is generating those is failing to include a single link. @apapadimoulis's turf?
-
RE: Perl: Review my code
Yeah, but a good chunk of the syllables are something I'd expect from Chinese transliterations, not Japanese. And there's no Chinese in the language list.
-
RE: Perl: Review my code
みんなが@translatorさんと遊びっぱなしになったらしいので、僕も少し遊んでみます。確かに日本語で書いたら、その翻訳の最初の言語は英語しかできないボットですが、こうしてどんな結果になるのかな。
I know the bot selects the intermediate languages by a dice roll, but I guess it can't handle it when the source language is not English, can it? Perhaps I'll get lucky and one of the languages hits.
(Oh, btw, I guess I'm wapanese.)
Edit: I guess the result was quite unexpected.
-
RE: Logged-out users get a blank screen of death
Oh, so the e-mail name comes from the forum's realname field. I was confused, because I got a notification e-mail with the following From: line
From: Brownies are Delicious™ use-the-contact-form@thedailywtf.com
-
RE: Perl: Review my code
It's a Perl custom to name private instance variables and methods with a leading underscore.[1] Although I'm not really sure about the instance variables part; most people don't go touching the privates of an object. I think it's just a poorly named instance variable -- it shouldn't need that underscore.
("Perl doesn't have an infatuation with enforced privacy. It would prefer that you stayed out of its living room because you weren't invited, not because it has a shotgun." -- perlmodlib)
It's a bit like with LaTeX, where module privates are marked with the
@
character.
[1] I mean, in the vanilla OO Perl offers. The OO modules available may implement real access restrictions.
-
RE: Perl: Review my code
Well, this function could indeed use some more love.
sub hand { my $self = shift; # bug my @hand = shift; # deprecated, emits a warning if (defined(@hand)) { # bug $self->{_hand} = @hand; } # possible bug return $self->{_hand}; }
I think you were confused on whether you wanted to deal with array references or actual arrays. I quite liked Ruby for a while since everything was a reference there, so there was no chance of confusion, until Perl's semantics finally clicked. I still like Ruby, but for other reasons. (Rails is not one of these reasons.)
If you wanted arrays, this is how the function should look:
sub hand { my $self = shift; my @hand = @_; if (@hand) { $self->{_hand} = \@hand; } return @{ $self->{_hand} }; }
If arrayrefs,
sub hand { my $self = shift; my $hand = shift; if ($hand) { $self->{_hand} = $hand; } return $self->{_hand}; }
It rather makes sense from Larry's linguist viewpoint. Singular subject comes with singular object. Plural comes with plural. If you mix
$
(singular) and@
(plural), it looks like a grammatical error / bug. -
RE: Perl: Review my code
Blind jeering is a common phenomenon in the industry. People who have never tried Lisp say it's unreadable because of the parens. People who have never tried Forth say it's just plain unreadable (they may have a point). People who have never tried Haskell say you have to have a PhD in Math to use it.
You know, I haven't seen any lisp code longer than a three-line snippet, so I don't really know how deep the parentheses go there, but I'm not entirely unconvinced they don't have a point. (Did I just make three negations?) I didn't have problems matching parens back when BASIC was the only language I had (age ten?), and I even enjoyed using handfuls of them, but nowadays, it's just a pain and I have to insert whitespace strategically to make any series of parens and paren-like symbols readable.
There's half a dozen of languages I'd like a working knowledge in, but since every language seems to take 2-3 years to reach fluency -- if using them exclusively --, I don't think I have enough time in my life for them. Haskell, incidentally, not being one of them.
-
RE: Perl: Review my code
No, it's not, it's assigned via position. Named arguments are like https://msdn.microsoft.com/en-us/library/dd264739.aspx
So like in Objective-C?
Perl does have named arguments then, in a way, if you parse the args list as a hash. The bad part is that you can't call the function 'normally' then, but you have to always name the arguments.
sub calculate_bmi { my (%args) = @_; return $args{weight} / (($args{height} / 100) ** 2) } # ...are we calculating this for a veeery obese baby? calculate_bmi(weight => 123, height => 64);
-
RE: Perl: Review my code
Lines that have never made much sense to me:
if (defined($nick)) { $self->{_nick} = $nick; }
What do the braces do in that line?
$self
is a hashref, as it most often is?if (defined(@hand)) { $self->{_hand} = @hand; }
Why is that line scalar context?
I haven't the faintest clue; I'd possibly treat that line as an error. It doesn't look right to me.
while (exists($game->{_dealt}{$rand})) { $rand = int(rand($Apples::nouncount)); }
Braces AND arrows now!
Hashref. A nested one.
[snip code] Approaching line noise rapidly, and I wrote the damn thing
...yeah.
foreach $player (sort {$self->{_players}{$b}->{_score} <=> $self->{_players}{$a}->{_score} } (keys %{$self->{_players}})) { Logios::IRC_print($where," " . $player . ": " .$self->{_players}{$player}->{_score}); }
I suspect my friend wrote that line for me.
Use a temp variable and ... it's still not readable but a tad better. Custom sorts can't be made pretty, if you ask me.
my $plrs = $self->{_players}; for $player ( sort { $plrs->{$b}->{_score} <=> $plrs->{$a}->{_score} } keys %$plrs ) { Logios:: ... $plrs->{$player}{_score}; }
-
RE: Perl: Review my code
mostly that many lines pass the 80-column mark,
That guideline is obsolete. Don't worry about it.
Well, I find longer line lengths difficult to read. That's really the only reason I try to adhere to it.
I noticed you almost (entirely?) avoided using RegEx, which is the thing that makes most Perl scripts into unreadable messes.
There's one. In the
split(/ /, $msg)
Not sure you can call it a real regexp though, when it's only a single character in length.
Anyway, not much text parsing in there so no need for regexps.
-
RE: Perl: Review my code
- Functions can't take named arguments?
``` sub random_item { my ($type) = @_; } ```</blockquote>
$type
is sort of a named argument. You see, Perl function calls take a list. The list is unpacked into named arguments, typically in the beginning of the function. It's often quite helpful if you ask me, but I'm sure it doesn't please the 'typed variables' crowd.- Functions and code are just strewn around the source file. Not much structure. Combined with previous point, it really reminds me more of a bash script than actual language.
Oh, that's a common fault of mine. I tend to group them as 'sub-functions' that are directly above the functions that need them.
- Is this a global var?
``` sub reset_game { %records = (</blockquote>
It is. Defined at the top of the file.
-
RE: Perl: Review my code
Yeah, I'm quite calm and generally ignoring them but I just can't help noticing that every time the language is mentioned, there's always someone blindly jeering. It's gotten old.
I know I've got at least one WTF in the code:
sub trophy {}
is too clever for my own sake.I'm fine even if you point and laugh at the code, as long as it's got some merit. So go ahead.
-
Perl: Review my code
About two years ago, I was helping out someone at Perlmonks, and in a bout of frustration I decided to rewrite/refactor his script because it was a mess.
Now, the popular opinion is that everything written in Perl looks like line noise. So I'd like feedback on what's wrong with the rewritten script. And which part of it looks like line noise. [1]
As I said in the post back then, I know it's got a couple of flaws; mostly that many lines pass the 80-column mark, and the three functions being practically identical in logic -- only the strings change.
Oh, and please disregard the toilet humour. It's not mine -- it's from the original script.
#!/usr/bin/perl # # Flashy's bloodsports. http://digdilem.org/ - "Because thems trouts ain't gonna catch themselves!" # (Credit to the original Eggdrop TCL script by Nerfbendr) # # Adds silly !hunt, !fish and !trophy and !present public triggers # Also !newmonth will clean out the trophy cupboard. (Only if you do it, or the nick in $owner_nick) # # Optional Configuration (Will work fine without changing these, but you can if you like) my $owner_nick='rainbowwarrior'; # Your nick - you can only reset the scores remotely if you use this nick. my $scale = 'kg'; # Say here whether you want to measure weights in lb or kg. my $catch_percent=90; # How often you catch or shoot something. my $trophy_cabinet = Xchat::get_info( 'xchatdir' ) . "\\trophies.txt"; # File to keep the trophies in. # End user configuration use strict; use warnings; use Storable qw/nstore retrieve/; Xchat::register( "rainbowwarrrior's Huntin' 'n Fishin' and present unwrapping", 'v.004', "Hunting", "" ); Xchat::hook_print('Channel Message', "hunting"); Xchat::hook_print('Your Message', "hunting"); Xchat::hook_print('Private Message', "hunting"); Xchat::hook_print('Private Message to Dialog', "hunting"); my %records; load_trophy(); Xchat::print("\002Loaded Flash's Huntin' 'n Fishin'\002 (!hunt, !fish !present !trophy - Current records are $records{fish}{weight}$scale and $records{hunt}{weight}$scale)"); my %items = ( hunt => ["bear","gopher","rabbit","hunter","deer","fox","duck","moose","pokemon named Pikachu","park ranger","Yogi Bear","Boo Boo Bear","dog named Benji","cow","raccoon","koala bear","camper","channel lamer"], fish => ["Salmon","Herring","Yellowfin Tuna","Pink Salmon","Chub","Barbel","Perch","Northern Pike","Brown Trout","Arctic Char","Roach","Brayling","Bleak","Cat Fish","Sun Fish","Old Tire","Rusty Tin Can","Genie Lamp","Love Message In A Bottle","Old Log","Rubber Boot","Dead Body","Loch Ness Monster","Old Fishing Lure","Piece of the Titanic","Chunk of Atlantis","Squid","Whale","Dolphin","Porpoise","Stingray","Submarine","Seal","Seahorse","Jellyfish","Starfish","Electric Eel","Great White Shark","Scuba Diver","X","Lag Monster","Virus","Soggy Pack of Smokes","Pile of Weed","Boat Anchor","Pair Of Floaties","Mermaid","Merman","Halibut","Tiddler","Sock","Trout"], present => ["a new car","cake","guitar","dvd","xbox360","playstation3","hairdryer","trampoline","dog","cat","electric shock game","a board game","a snake","tickets to a rock concert","a blowup doll","book"], ); my %places = ( hunt => ["in some bushes","in a hunting blind","in a hole","up in a tree","in a hiding place","out in the open","in the middle of a field","downtown","on a street corner","at the local mall"], fish => ["Stream","Lake","River","Pond","Ocean","Bathtub","Kiddie's Swimming Pool","Toilet","Pile of Vomit","Pool of Urine","Kitchen Sink","Bathroom Sink","Mud Puddle","Pail of Water","Bowl of Jell-O (tm)","Wash Basin","Rain Barrel","Aquarium","SnowBank","WaterFall","Cup of Coffee","Glass of Milk"], present => ["in a cupboard","under a xmas tree","in the liverroom","up in a tree","in a hiding place","out in the open","upstairs","on a boat","on a street corner","at the local mall"], ); my %last_users; @last_users{qw/hunt fish present/} = ("Nobody") x 3; sub reset_game { %records = ( hunt => { qw/type bear weight 0 where Bush who Nobody/ }, fish => { qw/type Trout weight 0 where Pool who Nobody/ }, present => { qw/type xmas weight 0 where everywhere who Nobody/ }, ); } sub random_place { my ($type) = @_; die "Wrong type of place" unless $places{$type}; my $ary = $places{$type}; return $ary->[int rand scalar @$ary]; } sub random_item { my ($type) = @_; die "Wrong type of item" unless $items{$type}; my $ary = $items{$type}; return $ary->[int rand scalar @$ary]; } sub random_weight { my ($type) = @_; die "Wrong type of record" unless $records{$type}; return int(rand($records{$type}{weight} + 10)) + 1; } sub hunt { my ($hunter) = @_; my $place = random_place('hunt'); my $game = random_item('game'); my @msgs = ( [PRIV => "You hide $place and wait for something to wander by...", ".", "..", "...", "You think you hear something and fire wildly in that direction!"] ); if (rand(100) > $catch_percent) { push @msgs, [PRIV => "Rats...you missed it, $hunter! Better luck next time!"]; push @msgs, [PUB => "$hunter is useless, they missed by a mile!"]; return @msgs; } my $weight = random_weight('hunt'); push @msgs, [PRIV => "Congratulations, $hunter! You just bagged yourself a $weight$scale $game!"]; push @msgs, [PUB => "$hunter just bagged a $weight$scale $game."]; if ($weight > $records{hunt}{weight}) { push @msgs, [PRIV => "Wow!!! That's a new record! Way to go, $hunter! Type !trophy to see it!"]; push @msgs, [PUB => "Wow! That breaks the old record of a $records{hunt}{weight}$scale $records{hunt}{type}! $hunter is amazing!"]; $records{hunt} = { weight => $weight, type => $game, who => $hunter, where => $place }; save_trophy(); } return @msgs; } sub fish { my ($hunter) = @_; my $place = random_place('fish'); my $fish = random_item('fish'); my @msgs = ( [PRIV => "You cast your line into a $place and wait for a bite...", ".", "..", "...", "You feel a tug on your line and reel it in..."] ); if (rand(100) > $catch_percent) { push @msgs, [PRIV => "Rats...it got away, $hunter! Better luck next time!"]; push @msgs, [PUB => "$hunter is useless, they failed to catch anything!"]; return @msgs; } my $weight = random_weight('fish'); push @msgs, [PRIV => "Congratulations, $hunter! You just caught yourself a $weight$scale $fish!"]; push @msgs, [PUB => "$hunter just caught a $weight$scale $fish"]; if ($weight > $records{fish}{weight}) { push @msgs, [PRIV => "Wow!!! That's a new record! Way to go, $hunter! Type !trophy to see it!"]; push @msgs, [PUB => "Brilliant! That breaks the old record of a $records{fish}{weight}$scale $records{fish}{type}! $hunter is the world's best!"]; $records{fish} = { weight => $weight, type => $fish, who => $hunter, where => $place }; save_trophy(); } return @msgs; } sub trophy { my %verbs = ( fish => [fishing => 'caught'], hunt => [hunting => 'bagged'], present => ['present unwrapping' => 'unwrapped'] ); return map { [ 'PUB', $_ ] } map { sprintf "%s holds the %s record when they %s a %s$scale %s", @$_ } map { [ @$_[0, 3, 4, 1, 2] ] } map { [ @{ $records{$_} }{qw/who weight type/}, @{ $verbs{$_} } ] } qw/fish hunt present/; } sub present { my ($hunter) = @_; my $place = random_place('present'); my $present = random_item('present'); my @msgs = ( [PRIV => "You unwrap your present from $place and see what you get...", ".", "..", "...", "You unwrap and see ..."] ); if (rand(100) > $catch_percent) { push @msgs, [PRIV => "Sorry no present this time $hunter! Better luck next time!"]; push @msgs, [PUB => "$hunter is useless, they failed to get a present!"]; return @msgs; } my $weight = random_weight('present'); push @msgs, [PRIV => "Congratulations, $hunter! You just unwrapped a $weight$scale $present!"]; push @msgs, [PUB => "$hunter just got a $weight$scale $present"]; if ($weight > $records{present}{weight}) { push @msgs, [PRIV => "Wow!!! That's a new record! Way to go, $hunter! Type !trophy to see it!"]; push @msgs, [PUB => "Brilliant! That breaks the old record of a $records{present}{weight}$scale $records{present}{type}! $hunter is the world's best!"]; $records{present} = { weight => $weight, type => $present, who => $hunter, where => $place }; save_trophy(); } return @msgs; } sub new_month { my ($hunter, $mynick) = @_; $hunter = lc $hunter; if (not ($hunter eq lc $owner_nick or $hunter eq $mynick)) { return [PUB => "Who are you, $hunter to tell me to change the month?"]; } reset_game(); save_trophy(); return [PUB => "It's a new month, all existing huntin' 'n fishin' and present unwrapping records are reset!"]; } sub check_hogging { my ($type, $hunter) = @_; if ($last_users{$type} eq $hunter) { return [PUB => "Stop hogging all the best pitches $hunter, let someone else try first!"]; } return; } sub load_trophy { reset_game(); retrieve(\%records, $trophy_cabinet) or do { save_trophy(); return; }; } sub save_trophy { nstore(\%records, $trophy_cabinet) or die "Bah! Can't open the trophy cabinet to push this 'ere trophy in!"; } my %triggers = ( hunt => \&hunt, fish => \&fish, trophy => \&trophy, present => \&present, newmonth => \&new_month, ); sub hunting { my ($who, $msg) = @{ $_[0] }; my @pubwords = split(/ /, $msg); my $trigger = substr( lc $pubwords[0], 1 ); my $func = $triggers{ $trigger }; return unless $func; my $hunter = Xchat::strip_code($who); my $channel = Xchat::get_info('channel'); my @msgs = check_hogging($trigger, $hunter); if (!@msgs) { @msgs = $func->($hunter, Xchat::get_info('nick')); } for my $msg (@msgs) { my $type = shift @$msg; if ($type eq 'PUB') { Xchat::command("msg $channel $_") for @$msg; } elsif ($type eq 'PRIV') { Xchat::command("msg $hunter $_") for @$msg; } else { Xchat::print("Unknown message type: $type"); } } }
Please follow the perlmonks link if discourse's overflowing div is too small for you. Or copypaste it to a real syntax-highlighted editor.
[1]: (Sorry, I think this topic came about because of the jab the front-page article took at Perl, again. It's a good language with a consistent design, if you ask me. It's just not the popular opinion.)
p.s. I'm not sure what's the copyright status on that script; it's someone else's script but the code is 95 % mine. Of course, I can't exactly prove that since I posted it anonymously back then, but...