Skip to content

Instantly share code, notes, and snippets.

@ssov
Created May 29, 2012 05:58
Show Gist options
  • Save ssov/2822856 to your computer and use it in GitHub Desktop.
Save ssov/2822856 to your computer and use it in GitHub Desktop.
mikutter Plugin - ShootingStar的ななにか
# coding: utf-8
# GUI
module Plugin::ShootingStar
def sts_activity_status(kind, title, args = {})
Plugin.call(:modify_sts_activity_status,
{ plugin: self,
kind: kind,
description: title }.merge(args))
end
def sts_activity_description(kind, title, args = {})
Plugin.call(:modify_sts_activity_description,
{ plugin: self,
kind: kind,
description: title }.merge(args))
end
end
class Plugin
include Plugin::ShootingStar
def self.sts_activity_status(kind, title, args = {})
Plugin.call(:modify_sts_activity_status,
{ plugin: self,
kind: kind,
description: title }.merge(args))
end
def self.sts_activity_description(kind, title, args = {})
Plugin.call(:modify_sts_activity_description,
{ plugin: self,
kind: kind,
description: title }.merge(args))
end
end
Plugin::create(:sts_friend_timeline) do
main = Gtk::VBox.new
ststimeline = Gtk::TimeLine.new
shell = Gtk::Table.new(1, 1)
description = Gtk::IntelligentTextview.new
status = Gtk::IntelligentTextview.new
main.closeup(status).closeup(description).
pack_start(shell.attach(ststimeline, 0, 1, 0, 1, Gtk::FILL|Gtk::SHRINK|Gtk::EXPAND, Gtk::FILL|Gtk::SHRINK|Gtk::EXPAND))
Plugin.call(:mui_tab_regist, main, 'STS Home Timeline', MUI::Skin.get("etc.png"))
on_modify_sts_activity_status do |params|
status.rewind(params[:description].to_s)
end
on_modify_sts_activity_description do |params|
description.rewind(params[:description].to_s)
end
self.add_event(:update){ |service, messages|
ststimeline.add(messages) }
end
# other
Plugin.create(:shootingstar) do
def point_up(p)
@now_point += p
UserConfig[:now_point] = @now_point
update_status()
level_up_check()
end
# 参考
# http://shootingstar067.com/app/level.c
def next_level_up_point()
sum = 0
@level.times do |i|
n = i * 100
if n > 0
sum += n * Math::log(n).truncate()
else
sum += 0
end
end
@next_level_point = sum
end
def level_up_check()
if @next_level_point <= @now_point
@level += 1
UserConfig[:level] = @level
Plugin.activity :system, "レベルが#{@level}にあがった!"
Plugin.sts_activity_description :system, "レベルが#{@level}にあがった!"
next_level_up_point()
update_status()
end
end
def update_status()
Plugin.sts_activity_status :system, "#{@level}LV, #{@now_point}EXP 〄つぎのレベルになるには #{@next_level_point - @now_point}ひつようじゃ〄"
end
@level = UserConfig[:level]
@now_point = UserConfig[:now_point]
@next_level_point = nil
if @level == nil || @now_point == nil
UserConfig[:level] = 1
UserConfig[:now_point] = 0
@level = 1
@now_point = 0
end
next_level_up_point()
update_status()
#Gtk::TimeLine.timelines[Gtk::TimeLine.timelines.length-2].destroy
on_favorite do |service, by, to|
p = 0
if by.is_me?
if to[:source] == "mikutter"
p= rand(151)+@level
point_up(p)
else
p = rand(101)
point_up(p)
end
Plugin.activity :favorite, "#{to.user.to_s}をふぁぼった。#{p.to_s}EXP獲得。"
Plugin.sts_activity_description :system, "#{to.user.to_s}をふぁぼった。#{p.to_s}EXP獲得。"
else
p = 10
point_up(p)
Plugin.sts_activity_description :system, "#{by[:idname]}にふぁぼられた。10EXP獲得。"
update_status()
end
if !to.user.is_me? and to.user != nil and by.is_me?
if rand(70) == 0
if to[:source] == "mikutter"
Post.primary_service.update(:message => "@#{to.user.to_s} ☝( ՞ਊ ՞)☝ 「またmikutterか…ザコめ…」#{" " * rand(10)}")
end
end
end
end
add_event_filter(:command){ |menu|
menu[:shootingstar] = {
:slug => :shootingstar,
:name => '(´〄ε〄`*)',
:condition => lambda{ |m| true },
:exec => lambda{ |m| Post.primary_service.update(:message => "(´〄ε〄`*) < #{@level.to_s}レベルなう #{" " * rand(10)}") },
:visible => true,
:role => :message }
[menu]
}
add_event_filter(:command){ |menu|
menu[:adventure] = {
:slug => :adventure,
:name => '冒険の書',
:condition => lambda{ |m| true },
:exec => lambda{ |m|
Plugin.activity :system, "つぎのレベルになるには あと#{@next_level_point - @now_point}のけいけんちが ひつようじゃ"
},
:visible => true,
:role => :message }
[menu]
}
next_level_up_point()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment