2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-24 01:50:20 -04:00
|
|
|
discobot_username = "discobot"
|
|
|
|
|
2020-05-06 11:28:02 -04:00
|
|
|
def seed_primary_email
|
2017-04-26 14:47:36 -04:00
|
|
|
UserEmail.seed do |ue|
|
2020-05-23 00:56:13 -04:00
|
|
|
ue.id = DiscourseNarrativeBot::BOT_USER_ID
|
2017-04-26 14:47:36 -04:00
|
|
|
ue.email = "discobot_email"
|
|
|
|
ue.primary = true
|
2020-05-23 00:56:13 -04:00
|
|
|
ue.user_id = DiscourseNarrativeBot::BOT_USER_ID
|
2017-04-26 14:47:36 -04:00
|
|
|
end
|
2017-11-23 10:54:40 -05:00
|
|
|
end
|
|
|
|
|
2020-05-23 00:56:13 -04:00
|
|
|
unless user = User.find_by(id: DiscourseNarrativeBot::BOT_USER_ID)
|
2017-11-23 10:54:40 -05:00
|
|
|
suggested_username = UserNameSuggester.suggest(discobot_username)
|
2017-04-26 14:47:36 -04:00
|
|
|
|
2020-05-06 11:28:02 -04:00
|
|
|
seed_primary_email
|
2017-11-23 11:00:47 -05:00
|
|
|
|
2017-05-24 01:50:20 -04:00
|
|
|
User.seed do |u|
|
2020-05-23 00:56:13 -04:00
|
|
|
u.id = DiscourseNarrativeBot::BOT_USER_ID
|
2017-05-24 01:50:20 -04:00
|
|
|
u.name = discobot_username
|
|
|
|
u.username = suggested_username
|
|
|
|
u.username_lower = suggested_username.downcase
|
|
|
|
u.password = SecureRandom.hex
|
|
|
|
u.active = true
|
|
|
|
u.approved = true
|
|
|
|
u.trust_level = TrustLevel[4]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-23 00:56:13 -04:00
|
|
|
bot = User.find(DiscourseNarrativeBot::BOT_USER_ID)
|
2017-11-23 10:54:40 -05:00
|
|
|
|
|
|
|
# ensure discobot has a primary email
|
|
|
|
unless bot.primary_email
|
2020-05-06 11:28:02 -04:00
|
|
|
seed_primary_email
|
2017-11-23 10:54:40 -05:00
|
|
|
bot.reload
|
|
|
|
end
|
|
|
|
|
2017-05-24 01:50:20 -04:00
|
|
|
bot.update!(admin: true, moderator: false)
|
|
|
|
|
2020-07-07 12:24:31 -04:00
|
|
|
bot.create_user_option! if !bot.user_option
|
|
|
|
|
2017-05-24 01:50:20 -04:00
|
|
|
bot.user_option.update!(
|
2019-03-15 10:55:11 -04:00
|
|
|
email_messages_level: UserOption.email_level_types[:never],
|
|
|
|
email_level: UserOption.email_level_types[:never],
|
2017-05-24 01:50:20 -04:00
|
|
|
)
|
|
|
|
|
2020-07-07 12:24:31 -04:00
|
|
|
bot.create_user_profile! if !bot.user_profile
|
|
|
|
|
2017-05-24 01:50:20 -04:00
|
|
|
if !bot.user_profile.bio_raw
|
2021-01-22 20:21:26 -05:00
|
|
|
bot.user_profile.update!(bio_raw: I18n.t("discourse_narrative_bot.bio"))
|
2017-05-24 01:50:20 -04:00
|
|
|
end
|
|
|
|
|
2020-05-23 00:56:13 -04:00
|
|
|
Group.user_trust_level_change!(DiscourseNarrativeBot::BOT_USER_ID, TrustLevel[4])
|