Skip to content

Commit

Permalink
improved faceswap
Browse files Browse the repository at this point in the history
  • Loading branch information
edelkas committed Nov 15, 2022
1 parent 186a0ac commit c81439f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions src/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c81439f

Please sign in to comment.