"Fossies" - the Fresh Open Source Software Archive

Member "discourse-2.8.3/plugins/discourse-narrative-bot/db/fixtures/001_discobot.rb" (14 Apr 2022, 1369 Bytes) of package /linux/www/discourse-2.8.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 # frozen_string_literal: true
    2 
    3 discobot_username = 'discobot'
    4 
    5 def seed_primary_email
    6   UserEmail.seed do |ue|
    7     ue.id = DiscourseNarrativeBot::BOT_USER_ID
    8     ue.email = "discobot_email"
    9     ue.primary = true
   10     ue.user_id = DiscourseNarrativeBot::BOT_USER_ID
   11   end
   12 end
   13 
   14 unless user = User.find_by(id: DiscourseNarrativeBot::BOT_USER_ID)
   15   suggested_username = UserNameSuggester.suggest(discobot_username)
   16 
   17   seed_primary_email
   18 
   19   User.seed do |u|
   20     u.id = DiscourseNarrativeBot::BOT_USER_ID
   21     u.name = discobot_username
   22     u.username = suggested_username
   23     u.username_lower = suggested_username.downcase
   24     u.password = SecureRandom.hex
   25     u.active = true
   26     u.approved = true
   27     u.trust_level = TrustLevel[4]
   28   end
   29 end
   30 
   31 bot = User.find(DiscourseNarrativeBot::BOT_USER_ID)
   32 
   33 # ensure discobot has a primary email
   34 unless bot.primary_email
   35   seed_primary_email
   36   bot.reload
   37 end
   38 
   39 bot.update!(admin: true, moderator: false)
   40 
   41 bot.create_user_option! if !bot.user_option
   42 
   43 bot.user_option.update!(
   44   email_messages_level: UserOption.email_level_types[:never],
   45   email_level: UserOption.email_level_types[:never]
   46 )
   47 
   48 bot.create_user_profile! if !bot.user_profile
   49 
   50 if !bot.user_profile.bio_raw
   51   bot.user_profile.update!(
   52     bio_raw: I18n.t('discourse_narrative_bot.bio')
   53   )
   54 end
   55 
   56 Group.user_trust_level_change!(DiscourseNarrativeBot::BOT_USER_ID, TrustLevel[4])