Skip to content

Instantly share code, notes, and snippets.

@jhsu
Created June 2, 2010 14:45
Show Gist options
  • Save jhsu/422455 to your computer and use it in GitHub Desktop.
Save jhsu/422455 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Author: Joseph "jshsu" Hsu <[email protected]>
# File: roll.rb
#
# weechat script to roll a die
#
# Copyright (C) 2010 Joseph Hsu
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
def weechat_init
Weechat.register('roll', 'jshsu', '0.1', 'GPL3', 'Roll Die and say in current channel', '', '')
Weechat.hook_command('roll', 'roll a die', '[max]', 'number of sides', '', 'roll', '')
return Weechat::WEECHAT_RC_OK
end
def roll(data, buffer, *args)
max = args.first.to_i
if max > 0
number = rand(max-1) + 1
Weechat.command(Weechat.current_buffer, "/me rolled a #{number} out of #{max}")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment