2017-07-27 21:20:09 -04:00
|
|
|
discobot_username = 'discobot'
|
2017-05-24 01:50:20 -04:00
|
|
|
|
2017-11-23 10:54:40 -05:00
|
|
|
def seed_primary_email
|
2017-04-26 14:47:36 -04:00
|
|
|
UserEmail.seed do |ue|
|
|
|
|
ue.id = -2
|
|
|
|
ue.email = "discobot_email"
|
|
|
|
ue.primary = true
|
|
|
|
ue.user_id = -2
|
|
|
|
end
|
2017-11-23 10:54:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
unless user = User.find_by(id: -2)
|
|
|
|
suggested_username = UserNameSuggester.suggest(discobot_username)
|
2017-04-26 14:47:36 -04:00
|
|
|
|
2017-11-23 11:00:47 -05:00
|
|
|
seed_primary_email
|
|
|
|
|
2017-05-24 01:50:20 -04:00
|
|
|
User.seed do |u|
|
|
|
|
u.id = -2
|
|
|
|
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
|
|
|
|
|
|
|
|
# TODO Pull the user avatar from that thread for now. In the future, pull it from a local file or from some central discobot repo.
|
|
|
|
if !Rails.env.test?
|
2017-06-09 11:01:48 -04:00
|
|
|
begin
|
|
|
|
UserAvatar.import_url_for_user(
|
|
|
|
"https://cdn.discourse.org/dev/uploads/default/original/2X/e/edb63d57a720838a7ce6a68f02ba4618787f2299.png",
|
|
|
|
User.find(-2),
|
|
|
|
override_gravatar: true
|
|
|
|
)
|
|
|
|
rescue
|
|
|
|
# In case the avatar can't be downloaded, don't fail seed
|
|
|
|
end
|
2017-05-24 01:50:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
bot = User.find(-2)
|
2017-11-23 10:54:40 -05:00
|
|
|
|
|
|
|
# ensure discobot has a primary email
|
|
|
|
unless bot.primary_email
|
|
|
|
seed_primary_email
|
|
|
|
bot.reload
|
|
|
|
end
|
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
bot.update!(admin: true, moderator: false)
|
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
|
|
|
)
|
|
|
|
|
|
|
|
if !bot.user_profile.bio_raw
|
|
|
|
bot.user_profile.update!(
|
|
|
|
bio_raw: I18n.t('discourse_narrative_bot.bio', site_title: SiteSetting.title, discobot_username: bot.username)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
Group.user_trust_level_change!(-2, TrustLevel[4])
|