discourse/db/fixtures/006_badges.rb

409 lines
11 KiB
Ruby
Raw Normal View History

require 'badge_queries'
2014-07-17 01:10:44 -05:00
BadgeGrouping.seed do |g|
g.id = BadgeGrouping::GettingStarted
2014-07-17 01:10:44 -05:00
g.name = "Getting Started"
g.default_position = 10
2014-07-17 01:10:44 -05:00
end
BadgeGrouping.seed do |g|
g.id = BadgeGrouping::Community
2014-07-17 01:10:44 -05:00
g.name = "Community"
g.default_position = 11
2014-07-17 01:10:44 -05:00
end
BadgeGrouping.seed do |g|
g.id = BadgeGrouping::Posting
2014-07-17 01:10:44 -05:00
g.name = "Posting"
g.default_position = 12
2014-07-17 01:10:44 -05:00
end
BadgeGrouping.seed do |g|
g.id = BadgeGrouping::TrustLevel
2014-07-17 01:10:44 -05:00
g.name = "Trust Level"
g.default_position = 13
2014-07-17 01:10:44 -05:00
end
BadgeGrouping.seed do |g|
g.id = BadgeGrouping::Other
2014-07-17 01:10:44 -05:00
g.name = "Other"
g.default_position = 14
2014-07-17 01:10:44 -05:00
end
# BUGFIX
2014-07-26 20:30:55 -05:00
Badge.exec_sql "UPDATE badges
2014-07-18 00:55:42 -05:00
SET badge_grouping_id = -1
WHERE NOT EXISTS (
SELECT 1 FROM badge_groupings g
WHERE g.id = badge_grouping_id
2014-07-26 20:30:55 -05:00
) OR (id < 100 AND badge_grouping_id = #{BadgeGrouping::Other} )"
2014-06-17 01:29:49 -05:00
# Trust level system badges.
trust_level_badges = [
2014-07-07 02:55:25 -05:00
{id: 1, name: "Basic User", type: BadgeType::Bronze},
2014-09-05 01:38:29 -05:00
{id: 2, name: "Member", type: BadgeType::Bronze},
{id: 3, name: "Regular", type: BadgeType::Silver},
{id: 4, name: "Leader", type: BadgeType::Gold}
]
trust_level_badges.each do |spec|
Badge.seed do |b|
b.id = spec[:id]
b.default_name = spec[:name]
b.badge_type_id = spec[:type]
b.query = BadgeQueries.trust_level(spec[:id])
b.default_badge_grouping_id = BadgeGrouping::TrustLevel
2014-07-21 21:46:31 -05:00
b.trigger = Badge::Trigger::TrustLevelChange
2014-09-05 01:38:29 -05:00
# allow title for tl3 and above
2014-07-29 17:46:46 -05:00
b.default_allow_title = spec[:id] > 2
b.default_icon = "fa-user"
b.system = true
end
end
Badge.seed do |b|
b.id = Badge::Reader
b.default_name = "Reader"
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = false
b.show_posts = false
b.query = BadgeQueries::Reader
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
b.auto_revoke = false
b.system = true
end
2014-07-11 02:32:29 -05:00
Badge.seed do |b|
2014-07-16 01:26:22 -05:00
b.id = Badge::ReadGuidelines
b.default_name = "Read Guidelines"
2014-07-11 02:32:29 -05:00
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = false
b.show_posts = false
b.query = BadgeQueries::ReadGuidelines
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
b.trigger = Badge::Trigger::UserChange
b.system = true
2014-07-11 02:32:29 -05:00
end
2014-07-09 20:18:02 -05:00
Badge.seed do |b|
b.id = Badge::FirstLink
b.default_name = "First Link"
2014-07-09 20:18:02 -05:00
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = true
b.show_posts = true
b.query = BadgeQueries::FirstLink
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
2014-07-21 21:46:31 -05:00
b.trigger = Badge::Trigger::PostRevision
b.system = true
2014-07-09 20:18:02 -05:00
end
2014-07-10 23:17:01 -05:00
Badge.seed do |b|
b.id = Badge::FirstQuote
b.default_name = "First Quote"
2014-07-10 23:17:01 -05:00
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = true
b.show_posts = true
b.query = BadgeQueries::FirstQuote
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
2014-07-21 21:46:31 -05:00
b.trigger = Badge::Trigger::PostRevision
b.system = true
2014-07-10 23:17:01 -05:00
end
2014-07-07 23:26:53 -05:00
Badge.seed do |b|
b.id = Badge::FirstLike
b.default_name = "First Like"
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = true
b.show_posts = true
b.query = BadgeQueries::FirstLike
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
2014-07-21 21:46:31 -05:00
b.trigger = Badge::Trigger::PostAction
b.system = true
end
Badge.seed do |b|
b.id = Badge::FirstFlag
b.default_name = "First Flag"
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = true
b.show_posts = false
b.query = BadgeQueries::FirstFlag
b.badge_grouping_id = BadgeGrouping::GettingStarted
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
2014-07-21 21:46:31 -05:00
b.trigger = Badge::Trigger::PostAction
2014-08-09 17:40:25 -05:00
b.auto_revoke = false
b.system = true
end
[
[Badge::Promoter,"Promoter",BadgeType::Bronze,1,0],
[Badge::Campaigner,"Campaigner",BadgeType::Silver,3,1],
[Badge::Champion,"Champion",BadgeType::Gold,5,2],
].each do |id, name, type, count, trust_level|
Badge.seed do |b|
b.id = id
b.default_name = name
b.default_icon = "fa-user-plus"
b.badge_type_id = type
b.multiple_grant = false
b.target_posts = false
b.show_posts = false
b.query = BadgeQueries.invite_badge(count,trust_level)
b.default_badge_grouping_id = BadgeGrouping::Community
# daily is good enough
b.trigger = Badge::Trigger::None
b.auto_revoke = true
b.system = true
end
end
Badge.seed do |b|
b.id = Badge::FirstShare
b.default_name = "First Share"
2014-07-07 23:26:53 -05:00
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = true
b.show_posts = true
b.query = BadgeQueries::FirstShare
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
# don't trigger for now, its too expensive
b.trigger = Badge::Trigger::None
b.system = true
2014-07-07 23:26:53 -05:00
end
[
[Badge::NiceShare, "Nice Share", BadgeType::Bronze, 25],
[Badge::GoodShare, "Good Share", BadgeType::Silver, 300],
[Badge::GreatShare, "Great Share", BadgeType::Gold, 1000],
].each do |spec|
id, name, level, count = spec
Badge.seed do |b|
b.id = id
b.default_name = name
b.badge_type_id = level
b.multiple_grant = true
b.target_posts = true
b.show_posts = true
b.query = BadgeQueries.sharing_badge(count)
b.default_badge_grouping_id = BadgeGrouping::Community
# don't trigger for now, its too expensive
b.trigger = Badge::Trigger::None
b.system = true
end
end
Badge.seed do |b|
b.id = Badge::Welcome
b.default_name = "Welcome"
2014-07-07 02:55:25 -05:00
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = true
b.show_posts = true
b.query = BadgeQueries::Welcome
b.default_badge_grouping_id = BadgeGrouping::Community
2014-07-21 21:46:31 -05:00
b.trigger = Badge::Trigger::PostAction
b.system = true
end
Badge.seed do |b|
b.id = Badge::Autobiographer
b.default_name = "Autobiographer"
2014-07-07 02:55:25 -05:00
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.query = BadgeQueries::Autobiographer
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
2014-07-21 21:46:31 -05:00
b.trigger = Badge::Trigger::UserChange
b.system = true
end
2014-07-07 02:55:25 -05:00
Badge.seed do |b|
b.id = Badge::Editor
b.default_name = "Editor"
2014-07-07 02:55:25 -05:00
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.query = BadgeQueries::Editor
b.badge_grouping_id = BadgeGrouping::GettingStarted
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
2014-07-21 21:46:31 -05:00
b.trigger = Badge::Trigger::PostRevision
b.system = true
2014-07-07 02:55:25 -05:00
end
2014-06-17 01:29:49 -05:00
#
# Like system badges.
like_badges = [
{id: Badge::NicePost, name: "Nice Post", type: BadgeType::Bronze},
{id: Badge::GoodPost, name: "Good Post", type: BadgeType::Silver},
{id: Badge::GreatPost, name: "Great Post", type: BadgeType::Gold},
{id: Badge::NiceTopic, name: "Nice Topic", type: BadgeType::Bronze, topic: true},
{id: Badge::GoodTopic, name: "Good Topic", type: BadgeType::Silver, topic: true},
{id: Badge::GreatTopic, name: "Great Topic", type: BadgeType::Gold, topic: true}
2014-06-17 01:29:49 -05:00
]
like_badges.each do |spec|
Badge.seed do |b|
b.id = spec[:id]
b.default_name = spec[:name]
2014-06-17 01:29:49 -05:00
b.badge_type_id = spec[:type]
b.multiple_grant = true
b.target_posts = true
b.show_posts = true
b.query = BadgeQueries.like_badge(Badge.like_badge_counts[spec[:id]], spec[:topic])
b.default_badge_grouping_id = BadgeGrouping::Posting
2014-07-21 21:46:31 -05:00
b.trigger = Badge::Trigger::PostAction
b.system = true
2014-06-17 01:29:49 -05:00
end
end
2015-02-18 12:30:07 -06:00
Badge.seed do |b|
b.id = Badge::OneYearAnniversary
2015-02-18 18:17:30 -06:00
b.default_name = "Anniversary"
b.default_icon = "fa-clock-o"
2015-02-19 14:39:49 -06:00
b.badge_type_id = BadgeType::Silver
b.query = BadgeQueries::OneYearAnniversary
2015-02-18 12:30:07 -06:00
b.default_badge_grouping_id = BadgeGrouping::Community
b.trigger = Badge::Trigger::None
b.auto_revoke = false
b.system = true
end
[
[Badge::PopularLink, "Popular Link", BadgeType::Bronze, 50],
[Badge::HotLink, "Hot Link", BadgeType::Silver, 300],
[Badge::FamousLink, "Famous Link", BadgeType::Gold, 1000],
].each do |spec|
id, name, level, count = spec
Badge.seed do |b|
b.id = id
b.default_name = name
b.badge_type_id = level
b.multiple_grant = true
b.target_posts = true
b.show_posts = true
b.query = BadgeQueries.linking_badge(count)
2016-03-25 11:21:24 -05:00
b.badge_grouping_id = BadgeGrouping::Posting
b.default_badge_grouping_id = BadgeGrouping::Posting
# don't trigger for now, its too expensive
b.trigger = Badge::Trigger::None
b.system = true
end
end
2016-03-16 12:03:17 -05:00
[
[Badge::Appreciated, "Appreciated", BadgeType::Bronze, 1, 20],
[Badge::Respected, "Respected", BadgeType::Silver, 2, 100],
[Badge::Admired, "Admired", BadgeType::Gold, 5, 300],
].each do |spec|
id, name, level, like_count, post_count = spec
Badge.seed do |b|
b.id = id
b.name = name
b.default_name = name
b.default_icon = "fa-heart"
b.badge_type_id = level
b.query = BadgeQueries.liked_posts(post_count, like_count)
2016-03-16 12:03:17 -05:00
b.default_badge_grouping_id = BadgeGrouping::Community
b.trigger = Badge::Trigger::None
b.auto_revoke = false
b.system = true
end
2016-03-15 13:46:21 -05:00
end
2016-03-16 12:48:14 -05:00
[
[Badge::ThankYou, "Thank You", BadgeType::Bronze, 20, 10],
[Badge::GivesBack, "Gives Back", BadgeType::Silver, 100, 100],
[Badge::Empathetic, "Empathetic", BadgeType::Gold, 500, 1000]
2016-03-16 12:48:14 -05:00
].each do |spec|
id, name, level, count, ratio = spec
Badge.seed do |b|
b.id = id
b.default_name = name
b.default_icon = "fa-heart"
b.badge_type_id = level
b.query = BadgeQueries.liked_back(count, ratio)
b.badge_grouping_id = BadgeGrouping::Community
2016-03-16 12:48:14 -05:00
b.default_badge_grouping_id = BadgeGrouping::Community
b.trigger = Badge::Trigger::None
b.auto_revoke = false
b.system = true
end
end
[
[Badge::OutOfLove, "Out of Love", BadgeType::Bronze, 1],
[Badge::HigherLove, "Higher Love", BadgeType::Silver, 5],
[Badge::CrazyInLove, "Crazy in Love", BadgeType::Gold, 20],
].each do |spec|
id, name, level, count = spec
Badge.seed do |b|
b.id = id
b.name = name
b.default_name = name
b.default_icon = "fa-heart"
b.badge_type_id = level
b.query = BadgeQueries.like_rate_limit(count)
b.badge_grouping_id = BadgeGrouping::Community
b.default_badge_grouping_id = BadgeGrouping::Community
b.trigger = Badge::Trigger::None
b.auto_revoke = false
b.system = true
end
2016-03-15 15:06:50 -05:00
end
Badge.seed do |b|
b.id = Badge::FirstMention
b.default_name = "First Mention"
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = true
b.show_posts = true
b.query = BadgeQueries::FirstMention
b.badge_grouping_id = BadgeGrouping::GettingStarted
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
b.trigger = Badge::Trigger::PostRevision
b.system = true
end
Badge.seed do |b|
b.id = Badge::FirstEmoji
b.default_name = "First Emoji"
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = true
b.show_posts = true
b.query = nil
b.badge_grouping_id = BadgeGrouping::GettingStarted
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
b.trigger = Badge::Trigger::PostProcessed
b.system = true
end
2016-04-12 13:09:59 -05:00
Badge.seed do |b|
b.id = Badge::FirstOnebox
b.default_name = "First Onebox"
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = true
b.show_posts = true
b.query = nil
b.badge_grouping_id = BadgeGrouping::GettingStarted
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
b.trigger = Badge::Trigger::PostProcessed
b.system = true
end
Badge.where("NOT system AND id < 100").each do |badge|
new_id = [Badge.maximum(:id) + 1, 100].max
old_id = badge.id
badge.update_columns(id: new_id)
UserBadge.where(badge_id: old_id).update_all(badge_id: new_id)
end