diff --git a/src/messages.rb b/src/messages.rb index 48853fe5..32d31edb 100644 --- a/src/messages.rb +++ b/src/messages.rb @@ -1041,11 +1041,19 @@ def thanks(event) end def faceswap(event) - filename = Dir.entries("images/avatars").select{ |f| File.file?("images/avatars/" + f) }.sample - file = File.open("images/avatars/" + filename) - $bot.profile.avatar = file - file.close - event << "Remember changing the avatar has a 10 minute cooldown!" + avatars = Dir.entries("images/avatars").select{ |f| File.file?("images/avatars/" + f) } + old_avatar = get_avatar + new_avatar = old_avatar + while new_avatar == old_avatar + new_avatar = avatars.sample + end + File::open("images/avatars/" + new_avatar) do |f| + $bot.profile.avatar = f + end +rescue + event << "Failed to change avatar, try again later. The avatar can only be changed 4 times every 10 minutes." +else + set_avatar(new_avatar) end def send_level_time(event) @@ -1272,7 +1280,7 @@ def send_twitch(event) # Add role to player (internal, for permission system, not related to Discord roles) def add_role(event) - perm = assert_permissions(event, ['botmaster']) + assert_permissions(event) msg = event.content user = parse_discord_user(msg) diff --git a/src/utils.rb b/src/utils.rb index 1b5dabd0..53c97494 100644 --- a/src/utils.rb +++ b/src/utils.rb @@ -161,6 +161,14 @@ def wavg(arr, w) arr.each_with_index.map{ |a, i| a*w[i] }.sum.to_f / w.sum end +def get_avatar + GlobalProperty.find_by(key: 'avatar').value +end + +def set_avatar(str) + GlobalProperty.find_by(key: 'avatar').update(value: str) +end + # Permission system: # Support for different roles (unrelated to Discord toles). Each role can # be determined by whichever system we choose (Discord user IDs, Discord