Written on September 15th 2009, 16:09 by sYnie
Some days ago I wrote a small irssi plugin, which automatically replies to specific words or phrases. It’s really basic, but I thought to post it anyway, as I couldn’t find any.
It’s based on the 8-ball plugin – so thanks to Patrik Jansson.
That’s the code:
use strict;
use vars qw($VERSION %IRSSI);
use Irssi qw(command_bind signal_add);
$VERSION = '1.00';
%IRSSI = (
authors => 'synie',
name => 'auto reply',
description => 'auto reply',
license => 'GPL',
);
sub own_question {
my ($server, $msg, $target) = @_;
question($server, $msg, "", $target);
}
sub public_question {
my ($server, $msg, $nick, $address, $target) = @_;
question($server, $msg, $nick, $target);
}
sub question($server, $msg, $nick, $target) {
my ($server, $msg, $nick, $target) = @_;
$_ = $msg;
my $answer = "";
// Edit this:
if (/^how are you?/i) {
$answer = "I'm fine, thanks.";
} elsif (/ping/i) {
$answer = "pong";
} elsif (/^I hate you/i) {
if ($nick ne "fishbot" and $nick ne "snailbot")
{
$server->command('kick '.$target.' '.$nick.' bye!');
return 0;
}
}
if ($answer)
{
$server->command('msg '.$target.' '.($nick ? $nick.': ' : '').$answer);
}
return 0;
}
signal_add("message public", "public_question");
signal_add("message own_public", "own_question");
Just c&p it into a file (e.g. called autoreply) located at ~/.irssi/scripts or ~/.irssi/scripts/autorun and load it via `/script load autoreply`. Make sure you edited the phrases you want to answer to automatically first – but I think this script is self-explanatory.
Written on June 12th 2007, 14:06 by sYnie
I’m working on a project where I have to use VB.NET to render some text. The problem is, that VB doesn’t provite block text justification by default. Using GDI+ it’s quite easy to get that managed. The resulting text will be displayed on a bitmap, which can be drawn to a picturebox etc. Here’s the code:
Sub BlockJustification(ByRef pic As Bitmap, ByVal txt As String, ByRef x As Short, ByRef y As Short, ByRef w As Short)
Dim g As Graphics
g = Graphics.FromImage(pic)
Dim fnt As New Font(”Times New Roman”, 10)
Dim cnty As Integer = 0
Dim ar As String() = txt.Split(Chr(10) + Chr(13))
For m As Integer = 0 To UBound(ar)
Dim newTxt As String = “”
Dim array As String() = ar(m).Split(” “)
For i As Integer = 0 To UBound(array)
Dim newTxtTmp As String = newTxt + array(i)
If g.MeasureString(newTxtTmp, fnt, 9999999).Width >= w Then
Dim spacearray As String() = newTxt.Split(” “)
Dim spacecnt As Integer = UBound(spacearray) – 1
If spacecnt < 1 Then
newTxt = newTxtTmp
Dim tobreake As String = “”
Do While True
If g.MeasureString(tobreake, fnt, 9999999).Width >= w Then
g.DrawString(tobreake, fnt, Brushes.Black, 0, cnty)
cnty += 15
tobreake = “”
If g.MeasureString(newTxt, fnt, 9999999).Width < = w Then
newTxt += ” ”
Exit Do
End If
End If
tobreake += newTxt.Substring(0, 1)
newTxt = newTxt.Substring(1, newTxt.Length – 1)
Loop
Else
Dim newTxtlength As Integer = 0
For n As Integer = 0 To UBound(spacearray) – 1
newTxtlength += g.MeasureString(spacearray(n), fnt, 9999999).Width
Next
Dim space As Integer = w – newTxtlength
Dim spaceperword As Integer = space / spacecnt
Dim cntmeasure As Integer = 0
Dim dotcnt As Integer = w – (newTxtlength + (spaceperword * spacecnt))
‘MsgBox(”space: ” + space.ToString + ” — wordspace: ” + spaceperword.ToString + ” — measure: ” + newTextlength.ToString + ” — width: ” + w.ToString + ” — spacecnt: ” + spacecnt.ToString + ” — dotcnt: ” + dotcnt.ToString + ” — txt: ‘” + newTxt + “‘”)
For n As Integer = 0 To UBound(spacearray) – 1
g.DrawString(spacearray(n), fnt, Brushes.Black, cntmeasure, cnty)
If n = 0 Then
cntmeasure = cntmeasure + dotcnt
End If
cntmeasure += g.MeasureString(spacearray(n), fnt, 9999999).Width + spaceperword
Next
g.DrawLine(Pens.Blue, cntmeasure – spaceperword, 0, cntmeasure – spaceperword, 300)
i -= 1
newTxt = “”
cnty += 15
End If
Else
newTxt += array(i) + ” ”
End If
Next
If Not newTxt = “” Then
g.DrawString(newTxt, fnt, Brushes.Black, 0, cnty)
cnty += 15
End If
Next
g.Dispose()
End Sub
Now you can use it like this:
Dim img As New Bitmap(500, 500)
BlockJustification(img, Text1.Text, 0, 0, 250)
PictureBox1.CreateGraphics.DrawImage(img, 0, 0)